From 17fe7bc9c8311f7e192385e47550607e61874528 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 10 Jun 2023 17:47:16 +0200 Subject: kernel: implement DUP_SEARCH (like unix's F_DUPFD) --- src/user/lib/fcntl.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/user/lib') diff --git a/src/user/lib/fcntl.c b/src/user/lib/fcntl.c index 89412a5..b2d8685 100644 --- a/src/user/lib/fcntl.c +++ b/src/user/lib/fcntl.c @@ -1,6 +1,9 @@ #include +#include +#include #include #include +#include #include @@ -11,7 +14,15 @@ int open(const char *path, int flags, ...) { } int fcntl(int fd, int cmd, ...) { - (void)fd; (void)cmd; - _klogf("failing fcntl(%d)", cmd); - return errno = ENOSYS, -1; + va_list argp; + va_start(argp, cmd); + if (cmd == F_DUPFD) { + int to = va_arg(argp, int); + va_end(argp); + return _sys_dup(fd, to, DUP_SEARCH); + } else { + va_end(argp); + _klogf("failing fcntl(%d)", cmd); + return errno = ENOSYS, -1; + } } -- cgit v1.2.3