diff --git a/headers/posix/fcntl.h b/headers/posix/fcntl.h index 47cf98e3c3..581d6c8e7d 100644 --- a/headers/posix/fcntl.h +++ b/headers/posix/fcntl.h @@ -64,6 +64,8 @@ #define O_SHLOCK 0x01000000 /* obtain shared lock */ #define O_EXLOCK 0x02000000 /* obtain exclusive lock */ +#define AT_FDCWD (-1) /* CWD FD for the *at() functions */ + /* advisory file locking */ @@ -81,9 +83,10 @@ extern "C" { #endif extern int creat(const char *path, mode_t mode); -extern int open(const char *pathname, int oflags, ...); +extern int open(const char *path, int openMode, ...); /* the third argument is the permissions of the created file when O_CREAT is passed in oflags */ +extern int openat(int fd, const char *path, int openMode, ...); extern int fcntl(int fd, int op, ...); diff --git a/src/system/libroot/posix/Jamfile b/src/system/libroot/posix/Jamfile index 22fbdf524b..dcacbf8465 100644 --- a/src/system/libroot/posix/Jamfile +++ b/src/system/libroot/posix/Jamfile @@ -16,6 +16,7 @@ MergeObject posix_main.o : dlfcn.c dirent.c errno.c + fcntl.cpp fnmatch.c glob.c inttypes.c diff --git a/src/system/libroot/posix/unistd/open.c b/src/system/libroot/posix/fcntl.cpp similarity index 58% rename from src/system/libroot/posix/unistd/open.c rename to src/system/libroot/posix/fcntl.cpp index 3503ed2a6e..886025b32d 100644 --- a/src/system/libroot/posix/unistd/open.c +++ b/src/system/libroot/posix/fcntl.cpp @@ -13,6 +13,7 @@ #include #include +#include #include @@ -33,21 +34,52 @@ creat(const char *path, mode_t mode) int open(const char *path, int openMode, ...) { - int status; int perms = 0; - va_list args; - if (openMode & O_CREAT) { + va_list args; va_start(args, openMode); perms = va_arg(args, int) & ~__gUmask; // adapt the permissions as required by POSIX va_end(args); } - status = _kern_open(-1, path, openMode, perms); + int status = _kern_open(-1, path, openMode, perms); if (status < 0) { errno = status; return -1; } return status; } + + +int +openat(int fd, const char *path, int openMode, ...) +{ + int perms = 0; + if (openMode & O_CREAT) { + va_list args; + va_start(args, openMode); + perms = va_arg(args, int) & ~__gUmask; + // adapt the permissions as required by POSIX + va_end(args); + } + + int status = _kern_open(fd, path, openMode, perms); + if (status < 0) { + errno = status; + return -1; + } + return status; +} + + +int +fcntl(int fd, int op, ...) +{ + va_list args; + va_start(args, op); + uint32 argument = va_arg(args, uint32); + va_end(args); + + RETURN_AND_SET_ERRNO(_kern_fcntl(fd, op, argument)); +} diff --git a/src/system/libroot/posix/unistd/Jamfile b/src/system/libroot/posix/unistd/Jamfile index d615e54b64..b5a972856b 100644 --- a/src/system/libroot/posix/unistd/Jamfile +++ b/src/system/libroot/posix/unistd/Jamfile @@ -14,7 +14,6 @@ MergeObject posix_unistd.o : dup.c exec.cpp _exit.c - fcntl.c fork.c getlogin.c getpagesize.c @@ -25,7 +24,6 @@ MergeObject posix_unistd.o : lseek.c mknod.c mount.c - open.c pause.c pipe.c process.c diff --git a/src/system/libroot/posix/unistd/fcntl.c b/src/system/libroot/posix/unistd/fcntl.c deleted file mode 100644 index fc15e72b90..0000000000 --- a/src/system/libroot/posix/unistd/fcntl.c +++ /dev/null @@ -1,37 +0,0 @@ -/* -** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ - - -#include -#include -#include - -#include - - -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; - - -int -fcntl(int fd, int op, ...) -{ - status_t status; - uint32 argument; - va_list args; - - va_start(args, op); - argument = va_arg(args, uint32); - va_end(args); - - status = _kern_fcntl(fd, op, argument); - - RETURN_AND_SET_ERRNO(status) -} -