aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_filedesc.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-25 21:59:24 -0400
committerIan Moffett <ian@osmora.org>2024-03-25 21:59:24 -0400
commitadd3e844cf9eaf49010fbee2aa73977086e47428 (patch)
tree358f06ac38e67ab9389e705803210227ddc0f4bc /sys/kern/kern_filedesc.c
parent51e23753f4e98ef278324e3ea13f9617fe3a7a80 (diff)
kernel: filedesc: Return status in fd_alloc()
It is better for fd_alloc() to return the status and have one of the arguments point to an output than have fd_alloc() return the allocated file descriptor just like that. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_filedesc.c')
-rw-r--r--sys/kern/kern_filedesc.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c
index 72f9c06..0037f55 100644
--- a/sys/kern/kern_filedesc.c
+++ b/sys/kern/kern_filedesc.c
@@ -111,9 +111,15 @@ do_write(struct vnode *vp, const char *buf, size_t count)
* Allocate a file descriptor.
*
* @td: Thread to allocate from, NULL for current thread.
+ * @fd_out: Pointer to allocated file descriptor output.
+ *
+ * This routine will create a new file descriptor
+ * table entry.
+ *
+ * Returns 0 on success.
*/
-struct filedesc *
-fd_alloc(struct proc *td)
+int
+fd_alloc(struct proc *td, struct filedesc **fd_out)
{
struct filedesc *fd;
@@ -131,15 +137,19 @@ fd_alloc(struct proc *td)
memset(fd, 0, sizeof(struct filedesc));
if (fd == NULL) {
- return NULL;
+ return -ENOMEM;
}
fd->fdno = i;
td->fds[i] = fd;
- return fd;
+
+ if (fd_out != NULL)
+ *fd_out = fd;
+
+ return 0;
}
- return NULL;
+ return -EMFILE;
}
/*