From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/fcntl/fcntl.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/libc/fcntl/fcntl.c (limited to 'lib/libc/fcntl/fcntl.c') diff --git a/lib/libc/fcntl/fcntl.c b/lib/libc/fcntl/fcntl.c new file mode 100644 index 00000000..ae213df5 --- /dev/null +++ b/lib/libc/fcntl/fcntl.c @@ -0,0 +1,37 @@ +#include +#include +#include + +int fcntl(int fildes, int cmd, ...) +{ + unsigned long arg; + va_list ap; + va_start(ap, cmd); + arg = va_arg(ap, unsigned long); + va_end(ap); + + if (cmd == F_DUPFD_CLOEXEC) { + int ret = syscall(fcntl, fildes, F_DUPFD_CLOEXEC, arg); + if (ret != -EINVAL) { + if (ret >= 0) + syscall(fcntl, ret, F_SETFD, FD_CLOEXEC); + return __syscall_ret(ret); + } + + ret = syscall(fcntl, fildes, F_DUPFD_CLOEXEC, 0); + if (ret != -EINVAL) { + if (ret >= 0) + __syscall(close, ret); + + return __syscall_ret(-EINVAL); + } + + ret = syscall(fcntl, fildes, F_DUPFD, arg); + if (ret >= 0) + syscall(fcntl, ret, F_SETFD, FD_CLOEXEC); + + return __syscall_ret(ret); + } + + return syscall(fcntl, fildes, cmd); +} -- cgit v1.2.3