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 #define __nolibc_open_flags(_flags) ((_flags) | O_LARGEFILE) 18 19 #define __nolibc_open_mode(_flags) \ 20 ({ \ 21 mode_t _mode; \ 22 va_list args; \ 23 \ 24 va_start(args, (_flags)); \ 25 _mode = va_arg(args, mode_t); \ 26 va_end(args); \ 27 \ 28 _mode; \ 29 }) 30 31 /* 32 * int openat(int dirfd, const char *path, int flags[, mode_t mode]); 33 */ 34 35 static __attribute__((unused)) 36 int _sys_openat(int dirfd, const char *path, int flags, mode_t mode) 37 { 38 return __nolibc_syscall4(__NR_openat, dirfd, path, flags, mode); 39 } 40 41 static __attribute__((unused)) 42 int openat(int dirfd, const char *path, int flags, ...) 43 { 44 return __sysret(_sys_openat(dirfd, path, __nolibc_open_flags(flags), 45 __nolibc_open_mode(flags))); 46 } 47 48 /* 49 * int open(const char *path, int flags[, mode_t mode]); 50 */ 51 52 static __attribute__((unused)) 53 int _sys_open(const char *path, int flags, mode_t mode) 54 { 55 return __nolibc_syscall4(__NR_openat, AT_FDCWD, path, flags, mode); 56 } 57 58 static __attribute__((unused)) 59 int open(const char *path, int flags, ...) 60 { 61 return __sysret(_sys_open(path, __nolibc_open_flags(flags), __nolibc_open_mode(flags))); 62 } 63 64 /* 65 * int creat(const char *path, mode_t mode); 66 */ 67 68 static __attribute__((unused)) 69 int creat(const char *path, mode_t mode) 70 { 71 return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode); 72 } 73 74 #endif /* _NOLIBC_FCNTL_H */ 75