diff --git a/kernel/src/sys/file.cpp b/kernel/src/sys/file.cpp index c227da3c..58df5f97 100644 --- a/kernel/src/sys/file.cpp +++ b/kernel/src/sys/file.cpp @@ -113,6 +113,25 @@ Result sys_fcntl(Registers*, SyscallArgs args) return (u64)new_fd; } + case F_GETFD: return (u64) !!(descriptor.flags & O_CLOEXEC); + case F_SETFD: { + int arg = (int)args[2]; + if (arg == FD_CLOEXEC) descriptor.flags |= O_CLOEXEC; + else + descriptor.flags &= ~O_CLOEXEC; + return 0; + } + case F_GETFL: return (u64)(descriptor.flags & ~O_CLOEXEC); + case F_SETFL: { + int arg = (int)args[2]; + + descriptor.flags &= ~(O_APPEND | O_NONBLOCK); + arg &= (O_APPEND | O_NONBLOCK); + + descriptor.flags |= arg; + + return 0; + } default: return err(EINVAL); } } diff --git a/libc/include/bits/fcntl.h b/libc/include/bits/fcntl.h index c2178168..218fb0bc 100644 --- a/libc/include/bits/fcntl.h +++ b/libc/include/bits/fcntl.h @@ -5,5 +5,11 @@ #define F_DUPFD 0 #define F_DUPFD_CLOEXEC 1 +#define F_GETFD 2 +#define F_SETFD 3 +#define F_SETFL 4 +#define F_GETFL 5 + +#define FD_CLOEXEC 1 #endif diff --git a/libc/include/bits/open-flags.h b/libc/include/bits/open-flags.h index c0f7e680..2b9e3e78 100644 --- a/libc/include/bits/open-flags.h +++ b/libc/include/bits/open-flags.h @@ -13,4 +13,6 @@ #define O_NONBLOCK 64 #define O_CLOEXEC 128 +#define O_ACCMODE O_RDWR + #endif