From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/fcntl/open.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/fcntl/open.c (limited to 'src/fcntl/open.c') diff --git a/src/fcntl/open.c b/src/fcntl/open.c new file mode 100644 index 0000000..4c3c827 --- /dev/null +++ b/src/fcntl/open.c @@ -0,0 +1,21 @@ +#include +#include +#include "syscall.h" + +int open(const char *filename, int flags, ...) +{ + mode_t mode = 0; + + if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + + int fd = __sys_open_cp(filename, flags, mode); + if (fd>=0 && (flags & O_CLOEXEC)) + __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); + + return __syscall_ret(fd); +} -- cgit v1.2.3