diff --git a/kernel/src/sys/stdio.cpp b/kernel/src/sys/stdio.cpp index a32e8d55..9ad01b8f 100644 --- a/kernel/src/sys/stdio.cpp +++ b/kernel/src/sys/stdio.cpp @@ -20,7 +20,7 @@ #define FNCTL_DUPFD 0 -void sys_fcntl(Context* context, int fd, int command, [[maybe_unused]] uintptr_t arg) +void sys_fcntl(Context* context, int fd, int command, uintptr_t arg) { if (fd >= TASK_MAX_FDS || fd < 0) { @@ -34,10 +34,14 @@ void sys_fcntl(Context* context, int fd, int command, [[maybe_unused]] uintptr_t return; } Descriptor& file = current_task->files[fd]; - if (command == FNCTL_DUPFD) // FIXME: If arg is greater than 0, return the lowest numbered available file descriptor - // greater than or equal to arg. + if (command == FNCTL_DUPFD) { - int dupfd = current_task->alloc_fd(); + if ((int)arg < 0 || (int)arg >= TASK_MAX_FDS) + { + context->rax = -EINVAL; + return; + } + int dupfd = current_task->alloc_fd_greater_than_or_equal((int)arg); if (dupfd < 0) { context->rax = -EMFILE;