fcntl(F_DUPFD): Allocate any file descriptor greater than or equal to arg
This commit is contained in:
parent
891651f2d6
commit
ce10fb5743
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user