1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2 /*
3 * fcntl definition for NOLIBC
4 * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
5 */
6
7 /* make sure to include all global symbols */
8 #include "nolibc.h"
9
10 #ifndef _NOLIBC_FCNTL_H
11 #define _NOLIBC_FCNTL_H
12
13 #include "arch.h"
14 #include "types.h"
15 #include "sys.h"
16
17 /*
18 * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
19 */
20
21 static __attribute__((unused))
sys_openat(int dirfd,const char * path,int flags,mode_t mode)22 int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
23 {
24 return my_syscall4(__NR_openat, dirfd, path, flags, mode);
25 }
26
27 static __attribute__((unused))
openat(int dirfd,const char * path,int flags,...)28 int openat(int dirfd, const char *path, int flags, ...)
29 {
30 mode_t mode = 0;
31
32 if (flags & O_CREAT) {
33 va_list args;
34
35 va_start(args, flags);
36 mode = va_arg(args, mode_t);
37 va_end(args);
38 }
39
40 return __sysret(sys_openat(dirfd, path, flags, mode));
41 }
42
43 /*
44 * int open(const char *path, int flags[, mode_t mode]);
45 */
46
47 static __attribute__((unused))
sys_open(const char * path,int flags,mode_t mode)48 int sys_open(const char *path, int flags, mode_t mode)
49 {
50 return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
51 }
52
53 static __attribute__((unused))
open(const char * path,int flags,...)54 int open(const char *path, int flags, ...)
55 {
56 mode_t mode = 0;
57
58 if (flags & O_CREAT) {
59 va_list args;
60
61 va_start(args, flags);
62 mode = va_arg(args, mode_t);
63 va_end(args);
64 }
65
66 return __sysret(sys_open(path, flags, mode));
67 }
68
69 #endif /* _NOLIBC_FCNTL_H */
70