summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
authordzwdz2023-06-10 17:47:16 +0200
committerdzwdz2023-06-10 17:47:16 +0200
commit17fe7bc9c8311f7e192385e47550607e61874528 (patch)
tree2e64187a886fa88c652e5df5e6b8e36e34609f7e /src/user/lib
parentede58f88397ad32f4d573d17811279735e2e386a (diff)
kernel: implement DUP_SEARCH (like unix's F_DUPFD)
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/fcntl.c17
1 files changed, 14 insertions, 3 deletions
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 <bits/panic.h>
+#include <camellia.h>
+#include <camellia/syscalls.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdarg.h>
#include <stdio.h>
@@ -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;
+ }
}