From 9b0f6b65957aa5969368e151556a994f8161995a Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 27 Oct 2022 07:55:59 +0200 Subject: [PATCH] Kernel, libc: Add O_EXCL --- kernel/src/sys/stdio.cpp | 12 ++++++++++++ libs/libc/include/fcntl.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/kernel/src/sys/stdio.cpp b/kernel/src/sys/stdio.cpp index d0cca5f6..a1be546b 100644 --- a/kernel/src/sys/stdio.cpp +++ b/kernel/src/sys/stdio.cpp @@ -21,6 +21,7 @@ #define OPEN_TRUNCATED 32 #define OPEN_CREATE 64 #define OPEN_APPEND 128 +#define OPEN_EXCL 256 #define SEEK_SET 0 #define SEEK_CUR 1 @@ -164,6 +165,17 @@ void sys_open(Context* context, const char* filename, int flags, mode_t) // FIXM context->rax = -ENOENT; return; } + else + { + bool excl = (flags & OPEN_EXCL) > 0; + + if (excl) + { + kfree(kfilename); + context->rax = -EEXIST; + return; + } + } bool can_read = (flags & OPEN_READ) > 0; bool can_write = (flags & OPEN_WRITE) > 0; diff --git a/libs/libc/include/fcntl.h b/libs/libc/include/fcntl.h index 0b709fa3..6d27ec4b 100644 --- a/libs/libc/include/fcntl.h +++ b/libs/libc/include/fcntl.h @@ -19,6 +19,8 @@ #define O_CREAT 64 /* Open the file for appending. */ #define O_APPEND 128 +/* Fail to open the file if it already exists. */ +#define O_EXCL 256 /* Duplicate a file descriptor. */ #define F_DUPFD 0