1#pragma once 2 3#ifdef __cplusplus 4extern "C" { 5#endif 6 7#include <features.h> 8 9#define __NEED_off_t 10#define __NEED_pid_t 11#define __NEED_mode_t 12 13#ifdef _GNU_SOURCE 14#define __NEED_size_t 15#define __NEED_ssize_t 16#define __NEED_struct_iovec 17#endif 18 19#include <bits/alltypes.h> 20 21struct flock { 22 short l_type; 23 short l_whence; 24 off_t l_start; 25 off_t l_len; 26 pid_t l_pid; 27}; 28 29int creat(const char*, mode_t); 30int fcntl(int, int, ...); 31int open(const char*, int, ...); 32int openat(int, const char*, int, ...); 33int posix_fadvise(int, off_t, off_t, int); 34int posix_fallocate(int, off_t, off_t); 35 36#define O_SEARCH O_PATH 37#define O_EXEC O_PATH 38 39// clang-format off 40#define O_ACCMODE (03 | O_SEARCH) 41#define O_RDONLY 00 42#define O_WRONLY 01 43#define O_RDWR 02 44 45// Flags which align with ZXIO_FS_* 46// system/ulib/fdio/unistd.c asserts that these flags are aligned 47// with the ZXIO_FS_* versions. 48#define O_CREAT 0x00010000 49#define O_EXCL 0x00020000 50#define O_TRUNC 0x00040000 51#define O_DIRECTORY 0x00080000 52#define O_APPEND 0x00100000 53#define O_PATH 0x00400000 54#ifdef _ALL_SOURCE 55#define O_NOREMOTE 0x00200000 56#define O_ADMIN 0x00000004 57#define O_PIPELINE 0x80000000 58#endif 59 60// Flags which do not align with ZXIO_FS_* 61#define O_NONBLOCK 0x00000010 62#define O_DSYNC 0x00000020 63#define O_SYNC (0x00000040 | O_DSYNC) 64#define O_RSYNC O_SYNC 65#define O_NOFOLLOW 0x00000080 66#define O_CLOEXEC 0x00000100 67#define O_NOCTTY 0x00000200 68#define O_ASYNC 0x00000400 69#define O_DIRECT 0x00000800 70#define O_LARGEFILE 0x00001000 71#define O_NOATIME 0x00002000 72#define O_TMPFILE 0x00004000 73 74// clang-format on 75 76#define O_NDELAY O_NONBLOCK 77 78#define F_DUPFD 0 79#define F_GETFD 1 80#define F_SETFD 2 81#define F_GETFL 3 82#define F_SETFL 4 83 84#define F_GETLK 5 85#define F_SETLK 6 86#define F_SETLKW 7 87 88#define F_SETOWN 8 89#define F_GETOWN 9 90#define F_SETSIG 10 91#define F_GETSIG 11 92 93#define F_SETOWN_EX 15 94#define F_GETOWN_EX 16 95 96#define F_GETOWNER_UIDS 17 97 98#define F_OFD_GETLK 36 99#define F_OFD_SETLK 37 100#define F_OFD_SETLKW 38 101 102#define F_DUPFD_CLOEXEC 1030 103 104#define F_RDLCK 0 105#define F_WRLCK 1 106#define F_UNLCK 2 107 108#define FD_CLOEXEC 1 109 110#define AT_FDCWD (-100) 111#define AT_SYMLINK_NOFOLLOW 0x100 112#define AT_REMOVEDIR 0x200 113#define AT_SYMLINK_FOLLOW 0x400 114#define AT_EACCESS 0x200 115 116#define POSIX_FADV_NORMAL 0 117#define POSIX_FADV_RANDOM 1 118#define POSIX_FADV_SEQUENTIAL 2 119#define POSIX_FADV_WILLNEED 3 120#define POSIX_FADV_DONTNEED 4 121#define POSIX_FADV_NOREUSE 5 122 123#undef SEEK_SET 124#undef SEEK_CUR 125#undef SEEK_END 126#define SEEK_SET 0 127#define SEEK_CUR 1 128#define SEEK_END 2 129 130#ifndef S_IRUSR 131#define S_ISUID 04000 132#define S_ISGID 02000 133#define S_ISVTX 01000 134#define S_IRUSR 0400 135#define S_IWUSR 0200 136#define S_IXUSR 0100 137#define S_IRWXU 0700 138#define S_IRGRP 0040 139#define S_IWGRP 0020 140#define S_IXGRP 0010 141#define S_IRWXG 0070 142#define S_IROTH 0004 143#define S_IWOTH 0002 144#define S_IXOTH 0001 145#define S_IRWXO 0007 146#endif 147 148#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 149#define AT_NO_AUTOMOUNT 0x800 150#define AT_EMPTY_PATH 0x1000 151 152#define FAPPEND O_APPEND 153#define FFSYNC O_FSYNC 154#define FASYNC O_ASYNC 155#define FNONBLOCK O_NONBLOCK 156#define FNDELAY O_NDELAY 157 158#define F_OK 0 159#define R_OK 4 160#define W_OK 2 161#define X_OK 1 162#define F_ULOCK 0 163#define F_LOCK 1 164#define F_TLOCK 2 165#define F_TEST 3 166 167#define F_SETLEASE 1024 168#define F_GETLEASE 1025 169#define F_NOTIFY 1026 170#define F_CANCELLK 1029 171#define F_SETPIPE_SZ 1031 172#define F_GETPIPE_SZ 1032 173#define F_ADD_SEALS 1033 174#define F_GET_SEALS 1034 175 176#define F_SEAL_SEAL 0x0001 177#define F_SEAL_SHRINK 0x0002 178#define F_SEAL_GROW 0x0004 179#define F_SEAL_WRITE 0x0008 180 181#define DN_ACCESS 0x00000001 182#define DN_MODIFY 0x00000002 183#define DN_CREATE 0x00000004 184#define DN_DELETE 0x00000008 185#define DN_RENAME 0x00000010 186#define DN_ATTRIB 0x00000020 187#define DN_MULTISHOT 0x80000000 188 189int lockf(int, int, off_t); 190#endif 191 192#if defined(_GNU_SOURCE) 193#define F_OWNER_TID 0 194#define F_OWNER_PID 1 195#define F_OWNER_PGRP 2 196#define F_OWNER_GID 2 197struct f_owner_ex { 198 int type; 199 pid_t pid; 200}; 201#define FALLOC_FL_KEEP_SIZE 1 202#define FALLOC_FL_PUNCH_HOLE 2 203#define SYNC_FILE_RANGE_WAIT_BEFORE 1 204#define SYNC_FILE_RANGE_WRITE 2 205#define SYNC_FILE_RANGE_WAIT_AFTER 4 206#define SPLICE_F_MOVE 1 207#define SPLICE_F_NONBLOCK 2 208#define SPLICE_F_MORE 4 209#define SPLICE_F_GIFT 8 210int fallocate(int, int, off_t, off_t); 211#define fallocate64 fallocate 212ssize_t readahead(int, off_t, size_t); 213int sync_file_range(int, off_t, off_t, unsigned); 214ssize_t vmsplice(int, const struct iovec*, size_t, unsigned); 215ssize_t splice(int, off_t*, int, off_t*, size_t, unsigned); 216ssize_t tee(int, int, size_t, unsigned); 217#define loff_t off_t 218#endif 219 220#ifdef __cplusplus 221} 222#endif 223