diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/fcntl/open.c | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/fcntl/open.c')
| -rw-r--r-- | lib/libc/fcntl/open.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/libc/fcntl/open.c b/lib/libc/fcntl/open.c new file mode 100644 index 00000000..dbdff8f9 --- /dev/null +++ b/lib/libc/fcntl/open.c @@ -0,0 +1,23 @@ +#include <fcntl.h> +#include <stdarg.h> +#include <syscall.h> + +int open(const char *path, int oflag, ...) +{ + long ret; + mode_t mode = 0; + + if ((oflag & O_CREAT)) { + va_list ap; + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + } + + ret = syscall(open, path, oflag, mode); + + if (ret >= 0 && (oflag & O_CLOEXEC)) + return syscall(fcntl, ret, F_SETFD, FD_CLOEXEC); + + return ret; +} |
