* 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

View File

@ -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, ...);

View File

@ -16,6 +16,7 @@ MergeObject posix_main.o :
dlfcn.c
dirent.c
errno.c
fcntl.cpp
fnmatch.c
glob.c
inttypes.c

View File

@ -13,6 +13,7 @@
#include <errno.h>
#include <syscalls.h>
#include <syscall_utils.h>
#include <umask.h>
@ -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));
}

View File

@ -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

View File

@ -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 <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)
}