* src/system/libroot/posix: Moved open.c and fcntl.c out of the unistd

directory, where they were misplaced, and joined them to fcntl.cpp.
* Added openat().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33976 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-11-10 11:15:35 +00:00
parent 126fd25b7a
commit 098906f1d4
5 changed files with 41 additions and 44 deletions
+4 -1
View File
@@ -64,6 +64,8 @@
#define O_SHLOCK 0x01000000 /* obtain shared lock */ #define O_SHLOCK 0x01000000 /* obtain shared lock */
#define O_EXLOCK 0x02000000 /* obtain exclusive lock */ #define O_EXLOCK 0x02000000 /* obtain exclusive lock */
#define AT_FDCWD (-1) /* CWD FD for the *at() functions */
/* advisory file locking */ /* advisory file locking */
@@ -81,9 +83,10 @@ extern "C" {
#endif #endif
extern int creat(const char *path, mode_t mode); 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 /* the third argument is the permissions of the created file when O_CREAT
is passed in oflags */ is passed in oflags */
extern int openat(int fd, const char *path, int openMode, ...);
extern int fcntl(int fd, int op, ...); extern int fcntl(int fd, int op, ...);
+1
View File
@@ -16,6 +16,7 @@ MergeObject posix_main.o :
dlfcn.c dlfcn.c
dirent.c dirent.c
errno.c errno.c
fcntl.cpp
fnmatch.c fnmatch.c
glob.c glob.c
inttypes.c inttypes.c
@@ -13,6 +13,7 @@
#include <errno.h> #include <errno.h>
#include <syscalls.h> #include <syscalls.h>
#include <syscall_utils.h>
#include <umask.h> #include <umask.h>
@@ -33,21 +34,52 @@ creat(const char *path, mode_t mode)
int int
open(const char *path, int openMode, ...) open(const char *path, int openMode, ...)
{ {
int status;
int perms = 0; int perms = 0;
va_list args;
if (openMode & O_CREAT) { if (openMode & O_CREAT) {
va_list args;
va_start(args, openMode); va_start(args, openMode);
perms = va_arg(args, int) & ~__gUmask; perms = va_arg(args, int) & ~__gUmask;
// adapt the permissions as required by POSIX // adapt the permissions as required by POSIX
va_end(args); va_end(args);
} }
status = _kern_open(-1, path, openMode, perms); int status = _kern_open(-1, path, openMode, perms);
if (status < 0) { if (status < 0) {
errno = status; errno = status;
return -1; return -1;
} }
return status; 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));
}
-2
View File
@@ -14,7 +14,6 @@ MergeObject posix_unistd.o :
dup.c dup.c
exec.cpp exec.cpp
_exit.c _exit.c
fcntl.c
fork.c fork.c
getlogin.c getlogin.c
getpagesize.c getpagesize.c
@@ -25,7 +24,6 @@ MergeObject posix_unistd.o :
lseek.c lseek.c
mknod.c mknod.c
mount.c mount.c
open.c
pause.c pause.c
pipe.c pipe.c
process.c process.c
-37
View File
@@ -1,37 +0,0 @@
/*
** Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <fcntl.h>
#include <stdarg.h>
#include <errno.h>
#include <syscalls.h>
#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)
}