libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / libroot / posix / fcntl.cpp
blob1a82dec02728de40c500944b0e825d2222ce39db
1 /*
2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001, Manuel J. Petit. All rights reserved.
6 * Distributed under the terms of the NewOS License.
7 */
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <pthread.h>
13 #include <stdarg.h>
14 #include <unistd.h>
16 #include <errno_private.h>
17 #include <syscalls.h>
18 #include <syscall_utils.h>
19 #include <umask.h>
22 int
23 creat(const char *path, mode_t mode)
25 RETURN_AND_SET_ERRNO_TEST_CANCEL(
26 _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask));
27 // adapt the permissions as required by POSIX
31 int
32 open(const char *path, int openMode, ...)
34 int perms = 0;
35 if (openMode & O_CREAT) {
36 va_list args;
37 va_start(args, openMode);
38 perms = va_arg(args, int) & ~__gUmask;
39 // adapt the permissions as required by POSIX
40 va_end(args);
43 RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(-1, path, openMode, perms));
47 int
48 openat(int fd, const char *path, int openMode, ...)
50 int perms = 0;
51 if (openMode & O_CREAT) {
52 va_list args;
53 va_start(args, openMode);
54 perms = va_arg(args, int) & ~__gUmask;
55 // adapt the permissions as required by POSIX
56 va_end(args);
59 RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(fd, path, openMode, perms));
63 int
64 fcntl(int fd, int op, ...)
66 va_list args;
67 va_start(args, op);
68 size_t argument = va_arg(args, size_t);
69 va_end(args);
71 status_t error = _kern_fcntl(fd, op, argument);
73 if (op == F_SETLKW)
74 pthread_testcancel();
76 RETURN_AND_SET_ERRNO(error);