1 #ifndef	_FCNTL_H
2 #define	_FCNTL_H
3 
4 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
5 #else
6 #include <__header_fcntl.h>
7 #endif
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <features.h>
13 
14 #define __NEED_off_t
15 #define __NEED_pid_t
16 #define __NEED_mode_t
17 
18 #ifdef _GNU_SOURCE
19 #define __NEED_size_t
20 #define __NEED_ssize_t
21 #define __NEED_struct_iovec
22 #endif
23 
24 #include <bits/alltypes.h>
25 
26 #include <bits/fcntl.h>
27 
28 struct flock {
29 	short l_type;
30 	short l_whence;
31 	off_t l_start;
32 	off_t l_len;
33 	pid_t l_pid;
34 };
35 
36 int creat(const char *, mode_t);
37 int fcntl(int, int, ...);
38 int open(const char *, int, ...);
39 int openat(int, const char *, int, ...);
40 int posix_fadvise(int, off_t, off_t, int);
41 int posix_fallocate(int, off_t, off_t);
42 
43 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
44 #define O_SEARCH   O_PATH
45 #define O_EXEC     O_PATH
46 #define O_TTY_INIT 0
47 
48 #define O_ACCMODE (03|O_SEARCH)
49 #define O_RDONLY  00
50 #define O_WRONLY  01
51 #define O_RDWR    02
52 
53 #define F_OFD_GETLK 36
54 #define F_OFD_SETLK 37
55 #define F_OFD_SETLKW 38
56 
57 #define F_DUPFD_CLOEXEC 1030
58 
59 #define F_RDLCK 0
60 #define F_WRLCK 1
61 #define F_UNLCK 2
62 
63 #define FD_CLOEXEC 1
64 
65 #define AT_FDCWD (-100)
66 #define AT_SYMLINK_NOFOLLOW 0x100
67 #define AT_REMOVEDIR 0x200
68 #define AT_SYMLINK_FOLLOW 0x400
69 #define AT_EACCESS 0x200
70 
71 #define POSIX_FADV_NORMAL     0
72 #define POSIX_FADV_RANDOM     1
73 #define POSIX_FADV_SEQUENTIAL 2
74 #define POSIX_FADV_WILLNEED   3
75 #ifndef POSIX_FADV_DONTNEED
76 #define POSIX_FADV_DONTNEED   4
77 #define POSIX_FADV_NOREUSE    5
78 #endif
79 
80 #undef SEEK_SET
81 #undef SEEK_CUR
82 #undef SEEK_END
83 #define SEEK_SET 0
84 #define SEEK_CUR 1
85 #define SEEK_END 2
86 
87 #ifndef S_IRUSR
88 #define S_ISUID 04000
89 #define S_ISGID 02000
90 #define S_ISVTX 01000
91 #define S_IRUSR 0400
92 #define S_IWUSR 0200
93 #define S_IXUSR 0100
94 #define S_IRWXU 0700
95 #define S_IRGRP 0040
96 #define S_IWGRP 0020
97 #define S_IXGRP 0010
98 #define S_IRWXG 0070
99 #define S_IROTH 0004
100 #define S_IWOTH 0002
101 #define S_IXOTH 0001
102 #define S_IRWXO 0007
103 #endif
104 
105 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
106 #define AT_NO_AUTOMOUNT 0x800
107 #define AT_EMPTY_PATH 0x1000
108 #define AT_STATX_SYNC_TYPE 0x6000
109 #define AT_STATX_SYNC_AS_STAT 0x0000
110 #define AT_STATX_FORCE_SYNC 0x2000
111 #define AT_STATX_DONT_SYNC 0x4000
112 #define AT_RECURSIVE 0x8000
113 
114 #define FAPPEND O_APPEND
115 #define FFSYNC O_SYNC
116 #define FASYNC O_ASYNC
117 #define FNONBLOCK O_NONBLOCK
118 #define FNDELAY O_NDELAY
119 
120 #define F_OK 0
121 #define R_OK 4
122 #define W_OK 2
123 #define X_OK 1
124 #define F_ULOCK 0
125 #define F_LOCK  1
126 #define F_TLOCK 2
127 #define F_TEST  3
128 
129 #define F_SETLEASE	1024
130 #define F_GETLEASE	1025
131 #define F_NOTIFY	1026
132 #define F_CANCELLK	1029
133 #define F_SETPIPE_SZ	1031
134 #define F_GETPIPE_SZ	1032
135 #define F_ADD_SEALS	1033
136 #define F_GET_SEALS	1034
137 
138 #define F_SEAL_SEAL	0x0001
139 #define F_SEAL_SHRINK	0x0002
140 #define F_SEAL_GROW	0x0004
141 #define F_SEAL_WRITE	0x0008
142 #define F_SEAL_FUTURE_WRITE	0x0010
143 
144 #define F_GET_RW_HINT		1035
145 #define F_SET_RW_HINT		1036
146 #define F_GET_FILE_RW_HINT	1037
147 #define F_SET_FILE_RW_HINT	1038
148 
149 #define RWF_WRITE_LIFE_NOT_SET	0
150 #define RWH_WRITE_LIFE_NONE	1
151 #define RWH_WRITE_LIFE_SHORT	2
152 #define RWH_WRITE_LIFE_MEDIUM	3
153 #define RWH_WRITE_LIFE_LONG	4
154 #define RWH_WRITE_LIFE_EXTREME	5
155 
156 #define DN_ACCESS	0x00000001
157 #define DN_MODIFY	0x00000002
158 #define DN_CREATE	0x00000004
159 #define DN_DELETE	0x00000008
160 #define DN_RENAME	0x00000010
161 #define DN_ATTRIB	0x00000020
162 #define DN_MULTISHOT	0x80000000
163 
164 int lockf(int, int, off_t);
165 #endif
166 #endif
167 
168 #if defined(_GNU_SOURCE)
169 #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */
170 #define F_OWNER_TID 0
171 #define F_OWNER_PID 1
172 #define F_OWNER_PGRP 2
173 #define F_OWNER_GID 2
174 struct file_handle {
175 	unsigned handle_bytes;
176 	int handle_type;
177 	unsigned char f_handle[];
178 };
179 #endif
180 #ifdef __wasilibc_unmodified_upstream /* WASI has no F_GETOWN_EX */
181 struct f_owner_ex {
182 	int type;
183 	pid_t pid;
184 };
185 #endif
186 #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */
187 #define FALLOC_FL_KEEP_SIZE 1
188 #define FALLOC_FL_PUNCH_HOLE 2
189 #endif
190 #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */
191 #define MAX_HANDLE_SZ 128
192 #endif
193 #ifdef __wasilibc_unmodified_upstream /* WASI has no syc_file_range */
194 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
195 #define SYNC_FILE_RANGE_WRITE 2
196 #define SYNC_FILE_RANGE_WAIT_AFTER 4
197 #endif
198 #ifdef __wasilibc_unmodified_upstream /* WASI has no splice */
199 #define SPLICE_F_MOVE 1
200 #define SPLICE_F_NONBLOCK 2
201 #define SPLICE_F_MORE 4
202 #define SPLICE_F_GIFT 8
203 #endif
204 #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */
205 int fallocate(int, int, off_t, off_t);
206 #define fallocate64 fallocate
207 #endif
208 #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */
209 int name_to_handle_at(int, const char *, struct file_handle *, int *, int);
210 int open_by_handle_at(int, struct file_handle *, int);
211 #endif
212 #ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */
213 ssize_t readahead(int, off_t, size_t);
214 #endif
215 #ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */
216 int sync_file_range(int, off_t, off_t, unsigned);
217 ssize_t vmsplice(int, const struct iovec *, size_t, unsigned);
218 ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned);
219 ssize_t tee(int, int, size_t, unsigned);
220 #endif
221 #define loff_t off_t
222 #endif
223 
224 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
225 #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */
226 #define F_GETLK64 F_GETLK
227 #define F_SETLK64 F_SETLK
228 #define F_SETLKW64 F_SETLKW
229 #define flock64 flock
230 #endif
231 #define open64 open
232 #define openat64 openat
233 #define creat64 creat
234 #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */
235 #define lockf64 lockf
236 #endif
237 #define posix_fadvise64 posix_fadvise
238 #define posix_fallocate64 posix_fallocate
239 #define off64_t off_t
240 #endif
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif
247