diff --git a/libs/libc/include/fcntl.h b/libs/libc/include/fcntl.h index 7aeaeae1..0af71315 100644 --- a/libs/libc/include/fcntl.h +++ b/libs/libc/include/fcntl.h @@ -1,6 +1,8 @@ #ifndef _FCNTL_H #define _FCNTL_H +#include + /* Open for reading only. */ #define O_RDONLY 1 /* Open for writing only. */ @@ -42,6 +44,10 @@ extern "C" /* Opens the file specified by pathname. Returns a file descriptor on success, or -1 on error. */ int open(const char* pathname, int flags, ...); + /* Opens the file specified by pathname, creating it if it doesn't exist or overwriting it otherwise. Calling this + * function is equivalent to calling open(pathname, O_WRONLY|O_CREAT|O_TRUNC, mode) */ + int creat(const char* pathname, mode_t mode); + /* Performs an operation on the file descriptor fd determined by cmd. */ int fcntl(int fd, int cmd, ...); diff --git a/libs/libc/src/fcntl.cpp b/libs/libc/src/fcntl.cpp index 0d37118c..c6a7d64d 100644 --- a/libs/libc/src/fcntl.cpp +++ b/libs/libc/src/fcntl.cpp @@ -15,6 +15,13 @@ extern "C" return (int)result; } + int creat(const char* pathname, mode_t mode) + { + return (int)__lc_fast_syscall3(SYS_open, pathname, O_WRONLY | O_CREAT | O_TRUNC, + mode); // we don't need to pass this through to open(), we can avoid variadic + // stuff since we're sure mode exists. + } + int fcntl(int fd, int cmd, ...) { va_list ap;