1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <unistd.h>
30 
31 #include "header_checks.h"
32 
unistd_h()33 static void unistd_h() {
34   MACRO(_POSIX_VERSION);
35   MACRO(_POSIX2_VERSION);
36   MACRO(_XOPEN_VERSION);
37 
38   MACRO(_POSIX_ADVISORY_INFO);
39   MACRO(_POSIX_ASYNCHRONOUS_IO);
40   MACRO(_POSIX_BARRIERS);
41   MACRO(_POSIX_CHOWN_RESTRICTED);
42   MACRO(_POSIX_CLOCK_SELECTION);
43   MACRO(_POSIX_CPUTIME);
44   MACRO(_POSIX_FSYNC);
45   MACRO(_POSIX_IPV6);
46   MACRO(_POSIX_JOB_CONTROL);
47   MACRO(_POSIX_MAPPED_FILES);
48   MACRO(_POSIX_MEMLOCK);
49   MACRO(_POSIX_MEMLOCK_RANGE);
50   MACRO(_POSIX_MEMORY_PROTECTION);
51   MACRO(_POSIX_MESSAGE_PASSING);
52   MACRO(_POSIX_MONOTONIC_CLOCK);
53   MACRO(_POSIX_NO_TRUNC);
54   MACRO(_POSIX_PRIORITIZED_IO);
55   MACRO(_POSIX_PRIORITY_SCHEDULING);
56   MACRO(_POSIX_RAW_SOCKETS);
57   MACRO(_POSIX_READER_WRITER_LOCKS);
58   MACRO(_POSIX_REALTIME_SIGNALS);
59   MACRO(_POSIX_REGEXP);
60   MACRO(_POSIX_SAVED_IDS);
61   MACRO(_POSIX_SEMAPHORES);
62   MACRO(_POSIX_SHARED_MEMORY_OBJECTS);
63   MACRO(_POSIX_SHELL);
64   MACRO(_POSIX_SPAWN);
65   MACRO(_POSIX_SPIN_LOCKS);
66   MACRO(_POSIX_SPORADIC_SERVER);
67   MACRO(_POSIX_SYNCHRONIZED_IO);
68   MACRO(_POSIX_THREAD_ATTR_STACKADDR);
69   MACRO(_POSIX_THREAD_ATTR_STACKSIZE);
70   MACRO(_POSIX_THREAD_CPUTIME);
71   MACRO(_POSIX_THREAD_PRIO_INHERIT);
72   MACRO(_POSIX_THREAD_PRIO_PROTECT);
73   MACRO(_POSIX_THREAD_PRIORITY_SCHEDULING);
74   MACRO(_POSIX_THREAD_PROCESS_SHARED);
75   MACRO(_POSIX_THREAD_ROBUST_PRIO_INHERIT);
76   MACRO(_POSIX_THREAD_ROBUST_PRIO_PROTECT);
77   MACRO(_POSIX_THREAD_SAFE_FUNCTIONS);
78   MACRO(_POSIX_THREAD_SPORADIC_SERVER);
79   MACRO(_POSIX_THREADS);
80   MACRO(_POSIX_TIMEOUTS);
81   MACRO(_POSIX_TIMERS);
82   MACRO(_POSIX_TYPED_MEMORY_OBJECTS);
83   MACRO(_POSIX2_C_BIND);
84   MACRO(_POSIX2_CHAR_TERM);
85   MACRO(_POSIX2_LOCALEDEF);
86   MACRO(_POSIX2_SW_DEV);
87 #if 0 // No libc I can find actually has this.
88   MACRO(_POSIX2_UPE);
89 #endif
90   MACRO(_XOPEN_CRYPT);
91   MACRO(_XOPEN_ENH_I18N);
92   MACRO(_XOPEN_REALTIME);
93   MACRO(_XOPEN_REALTIME_THREADS);
94   MACRO(_XOPEN_SHM);
95   MACRO(_XOPEN_UNIX);
96 #if defined(_XOPEN_UUCP)
97 #if _XOPEN_UUCP != -1 && _XOPEN_UUCP != 0 && _XOPEN_UUCP != 200809L
98 #error _XOPEN_UUCP
99 #endif
100 #endif
101 
102   MACRO(NULL);
103 
104   MACRO(F_OK);
105   MACRO(R_OK);
106   MACRO(W_OK);
107   MACRO(X_OK);
108 
109 #if !defined(__BIONIC__) // No confstr on Android.
110   MACRO(_CS_PATH);
111   MACRO(_CS_POSIX_V7_ILP32_OFF32_CFLAGS);
112   MACRO(_CS_POSIX_V7_ILP32_OFF32_LDFLAGS);
113   MACRO(_CS_POSIX_V7_ILP32_OFF32_LIBS);
114   MACRO(_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS);
115   MACRO(_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS);
116   MACRO(_CS_POSIX_V7_ILP32_OFFBIG_LIBS);
117   MACRO(_CS_POSIX_V7_LP64_OFF64_CFLAGS);
118   MACRO(_CS_POSIX_V7_LP64_OFF64_LDFLAGS);
119   MACRO(_CS_POSIX_V7_LP64_OFF64_LIBS);
120   MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS);
121   MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS);
122   MACRO(_CS_POSIX_V7_LPBIG_OFFBIG_LIBS);
123   MACRO(_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS);
124   MACRO(_CS_V7_ENV);
125 #endif
126 
127   MACRO(SEEK_CUR);
128   MACRO(SEEK_END);
129   MACRO(SEEK_SET);
130 
131   MACRO(F_LOCK);
132   MACRO(F_TEST);
133   MACRO(F_TLOCK);
134   MACRO(F_ULOCK);
135 
136   MACRO(_PC_2_SYMLINKS);
137   MACRO(_PC_ALLOC_SIZE_MIN);
138   MACRO(_PC_ASYNC_IO);
139   MACRO(_PC_CHOWN_RESTRICTED);
140   MACRO(_PC_FILESIZEBITS);
141   MACRO(_PC_LINK_MAX);
142   MACRO(_PC_MAX_CANON);
143   MACRO(_PC_MAX_INPUT);
144   MACRO(_PC_NAME_MAX);
145   MACRO(_PC_NO_TRUNC);
146   MACRO(_PC_PATH_MAX);
147   MACRO(_PC_PIPE_BUF);
148   MACRO(_PC_PRIO_IO);
149   MACRO(_PC_REC_INCR_XFER_SIZE);
150   MACRO(_PC_REC_MAX_XFER_SIZE);
151   MACRO(_PC_REC_MIN_XFER_SIZE);
152   MACRO(_PC_REC_XFER_ALIGN);
153   MACRO(_PC_SYMLINK_MAX);
154   MACRO(_PC_SYNC_IO);
155 #if 0 // No libc I can find actually has this.
156   MACRO(_PC_TIMESTAMP_RESOLUTION);
157 #endif
158   MACRO(_PC_VDISABLE);
159 
160   MACRO(_SC_2_C_BIND);
161   MACRO(_SC_2_C_DEV);
162   MACRO(_SC_2_CHAR_TERM);
163   MACRO(_SC_2_FORT_DEV);
164   MACRO(_SC_2_FORT_RUN);
165   MACRO(_SC_2_LOCALEDEF);
166   MACRO(_SC_2_SW_DEV);
167   MACRO(_SC_2_UPE);
168   MACRO(_SC_2_VERSION);
169   MACRO(_SC_ADVISORY_INFO);
170   MACRO(_SC_AIO_LISTIO_MAX);
171   MACRO(_SC_AIO_MAX);
172   MACRO(_SC_AIO_PRIO_DELTA_MAX);
173   MACRO(_SC_ARG_MAX);
174   MACRO(_SC_ASYNCHRONOUS_IO);
175   MACRO(_SC_ATEXIT_MAX);
176   MACRO(_SC_BARRIERS);
177   MACRO(_SC_BC_BASE_MAX);
178   MACRO(_SC_BC_DIM_MAX);
179   MACRO(_SC_BC_SCALE_MAX);
180   MACRO(_SC_BC_STRING_MAX);
181   MACRO(_SC_CHILD_MAX);
182   MACRO(_SC_CLK_TCK);
183   MACRO(_SC_CLOCK_SELECTION);
184   MACRO(_SC_COLL_WEIGHTS_MAX);
185   MACRO(_SC_CPUTIME);
186   MACRO(_SC_DELAYTIMER_MAX);
187   MACRO(_SC_EXPR_NEST_MAX);
188   MACRO(_SC_FSYNC);
189   MACRO(_SC_GETGR_R_SIZE_MAX);
190   MACRO(_SC_GETPW_R_SIZE_MAX);
191   MACRO(_SC_HOST_NAME_MAX);
192   MACRO(_SC_IOV_MAX);
193   MACRO(_SC_IPV6);
194   MACRO(_SC_JOB_CONTROL);
195   MACRO(_SC_LINE_MAX);
196   MACRO(_SC_LOGIN_NAME_MAX);
197   MACRO(_SC_MAPPED_FILES);
198   MACRO(_SC_MEMLOCK);
199   MACRO(_SC_MEMLOCK_RANGE);
200   MACRO(_SC_MEMORY_PROTECTION);
201   MACRO(_SC_MESSAGE_PASSING);
202   MACRO(_SC_MONOTONIC_CLOCK);
203   MACRO(_SC_MQ_OPEN_MAX);
204   MACRO(_SC_MQ_PRIO_MAX);
205   MACRO(_SC_NGROUPS_MAX);
206   MACRO(_SC_OPEN_MAX);
207   MACRO(_SC_PAGE_SIZE);
208   MACRO(_SC_PAGESIZE);
209   MACRO(_SC_PRIORITIZED_IO);
210   MACRO(_SC_PRIORITY_SCHEDULING);
211   MACRO(_SC_RAW_SOCKETS);
212   MACRO(_SC_RE_DUP_MAX);
213   MACRO(_SC_READER_WRITER_LOCKS);
214   MACRO(_SC_REALTIME_SIGNALS);
215   MACRO(_SC_REGEXP);
216   MACRO(_SC_RTSIG_MAX);
217   MACRO(_SC_SAVED_IDS);
218   MACRO(_SC_SEM_NSEMS_MAX);
219   MACRO(_SC_SEM_VALUE_MAX);
220   MACRO(_SC_SEMAPHORES);
221   MACRO(_SC_SHARED_MEMORY_OBJECTS);
222   MACRO(_SC_SHELL);
223   MACRO(_SC_SIGQUEUE_MAX);
224   MACRO(_SC_SPAWN);
225   MACRO(_SC_SPIN_LOCKS);
226   MACRO(_SC_SPORADIC_SERVER);
227   MACRO(_SC_SS_REPL_MAX);
228   MACRO(_SC_STREAM_MAX);
229   MACRO(_SC_SYMLOOP_MAX);
230   MACRO(_SC_SYNCHRONIZED_IO);
231   MACRO(_SC_THREAD_ATTR_STACKADDR);
232   MACRO(_SC_THREAD_ATTR_STACKSIZE);
233   MACRO(_SC_THREAD_CPUTIME);
234   MACRO(_SC_THREAD_DESTRUCTOR_ITERATIONS);
235   MACRO(_SC_THREAD_KEYS_MAX);
236   MACRO(_SC_THREAD_PRIO_INHERIT);
237   MACRO(_SC_THREAD_PRIO_PROTECT);
238   MACRO(_SC_THREAD_PRIORITY_SCHEDULING);
239   MACRO(_SC_THREAD_PROCESS_SHARED);
240   MACRO(_SC_THREAD_ROBUST_PRIO_INHERIT);
241   MACRO(_SC_THREAD_ROBUST_PRIO_PROTECT);
242   MACRO(_SC_THREAD_SAFE_FUNCTIONS);
243   MACRO(_SC_THREAD_SPORADIC_SERVER);
244   MACRO(_SC_THREAD_STACK_MIN);
245   MACRO(_SC_THREAD_THREADS_MAX);
246   MACRO(_SC_THREADS);
247   MACRO(_SC_TIMEOUTS);
248   MACRO(_SC_TIMER_MAX);
249   MACRO(_SC_TIMERS);
250   MACRO(_SC_TRACE);
251   MACRO(_SC_TRACE_EVENT_FILTER);
252   MACRO(_SC_TRACE_EVENT_NAME_MAX);
253   MACRO(_SC_TRACE_INHERIT);
254   MACRO(_SC_TRACE_LOG);
255   MACRO(_SC_TRACE_NAME_MAX);
256   MACRO(_SC_TRACE_SYS_MAX);
257   MACRO(_SC_TRACE_USER_EVENT_MAX);
258   MACRO(_SC_TYPED_MEMORY_OBJECTS);
259   MACRO(_SC_TZNAME_MAX);
260   MACRO(_SC_V7_ILP32_OFF32);
261   MACRO(_SC_VERSION);
262   MACRO(_SC_XOPEN_CRYPT);
263   MACRO(_SC_XOPEN_ENH_I18N);
264   MACRO(_SC_XOPEN_REALTIME);
265   MACRO(_SC_XOPEN_REALTIME_THREADS);
266   MACRO(_SC_XOPEN_SHM);
267   MACRO(_SC_XOPEN_STREAMS);
268   MACRO(_SC_XOPEN_UNIX);
269 #if 0 // No libc I can find actually has this.
270   MACRO(_SC_XOPEN_UUCP);
271 #endif
272   MACRO(_SC_XOPEN_VERSION);
273 
274   MACRO_VALUE(STDERR_FILENO, 2);
275   MACRO_VALUE(STDIN_FILENO, 0);
276   MACRO_VALUE(STDOUT_FILENO, 1);
277 
278   MACRO(_POSIX_VDISABLE);
279 
280   TYPE(size_t);
281   TYPE(ssize_t);
282   TYPE(uid_t);
283   TYPE(gid_t);
284   TYPE(off_t);
285   TYPE(pid_t);
286   TYPE(intptr_t);
287 
288   FUNCTION(access, int (*f)(const char*, int));
289   FUNCTION(alarm, unsigned (*f)(unsigned));
290   FUNCTION(chdir, int (*f)(const char*));
291   FUNCTION(chown, int (*f)(const char*, uid_t, gid_t));
292   FUNCTION(close, int (*f)(int));
293 #if !defined(__BIONIC__)
294   FUNCTION(confstr, size_t (*f)(int, char*, size_t));
295   FUNCTION(crypt, char* (*f)(const char*, const char*));
296 #endif
297   FUNCTION(dup, int (*f)(int));
298   FUNCTION(dup2, int (*f)(int, int));
299   FUNCTION(_exit, void (*f)(int));
300 #if !defined(__BIONIC__)
301   FUNCTION(encrypt, void (*f)(char[64], int));
302 #endif
303   FUNCTION(execl, int (*f)(const char*, const char*, ...));
304   FUNCTION(execle, int (*f)(const char*, const char*, ...));
305   FUNCTION(execlp, int (*f)(const char*, const char*, ...));
306   FUNCTION(execv, int (*f)(const char*, char* const[]));
307   FUNCTION(execve, int (*f)(const char*, char* const[], char* const[]));
308   FUNCTION(execvp, int (*f)(const char*, char* const[]));
309   FUNCTION(faccessat, int (*f)(int, const char*, int, int));
310   FUNCTION(fchdir, int (*f)(int));
311   FUNCTION(fchown, int (*f)(int, uid_t, gid_t));
312   FUNCTION(fchownat, int (*f)(int, const char*, uid_t, gid_t, int));
313   FUNCTION(fdatasync, int (*f)(int));
314   FUNCTION(fexecve, int (*f)(int, char* const[], char* const[]));
315   FUNCTION(fork, pid_t (*f)(void));
316   FUNCTION(fpathconf, long (*f)(int, int));
317   FUNCTION(fsync, int (*f)(int));
318   FUNCTION(ftruncate, int (*f)(int, off_t));
319   FUNCTION(getcwd, char* (*f)(char*, size_t));
320   FUNCTION(getegid, gid_t (*f)(void));
321   FUNCTION(geteuid, uid_t (*f)(void));
322   FUNCTION(getgid, gid_t (*f)(void));
323   FUNCTION(getgroups, int (*f)(int, gid_t[]));
324 #if !defined(__BIONIC__)
325   FUNCTION(gethostid, long (*f)(void));
326 #endif
327   FUNCTION(gethostname, int (*f)(char*, size_t));
328   FUNCTION(getlogin, char* (*f)(void));
329   FUNCTION(getlogin_r, int (*f)(char*, size_t));
330   FUNCTION(getopt, int (*f)(int, char* const[], const char*));
331   FUNCTION(getpgid, pid_t (*f)(pid_t));
332   FUNCTION(getpgrp, pid_t (*f)(void));
333   FUNCTION(getpid, pid_t (*f)(void));
334   FUNCTION(getppid, pid_t (*f)(void));
335   FUNCTION(getsid, pid_t (*f)(pid_t));
336   FUNCTION(getuid, uid_t (*f)(void));
337   FUNCTION(isatty, int (*f)(int));
338   FUNCTION(lchown, int (*f)(const char*, uid_t, gid_t));
339   FUNCTION(link, int (*f)(const char*, const char*));
340   FUNCTION(linkat, int (*f)(int, const char*, int, const char*, int));
341   FUNCTION(lockf, int (*f)(int, int, off_t));
342   FUNCTION(lseek, off_t (*f)(int, off_t, int));
343   FUNCTION(nice, int (*f)(int));
344   FUNCTION(pathconf, long (*f)(const char*, int));
345   FUNCTION(pause, int (*f)(void));
346   FUNCTION(pipe, int (*f)(int[2]));
347   FUNCTION(pread, ssize_t (*f)(int, void*, size_t, off_t));
348   FUNCTION(pwrite, ssize_t (*f)(int, const void*, size_t, off_t));
349   FUNCTION(read, ssize_t (*f)(int, void*, size_t));
350   FUNCTION(readlink, ssize_t (*f)(const char*, char*, size_t));
351   FUNCTION(readlinkat, ssize_t (*f)(int, const char*, char*, size_t));
352   FUNCTION(rmdir, int (*f)(const char*));
353   FUNCTION(setegid, int (*f)(gid_t));
354   FUNCTION(seteuid, int (*f)(uid_t));
355   FUNCTION(setgid, int (*f)(gid_t));
356   FUNCTION(setpgid, int (*f)(pid_t, pid_t));
357   FUNCTION(setpgrp, pid_t (*f)(void));
358   FUNCTION(setregid, int (*f)(gid_t, gid_t));
359   FUNCTION(setreuid, int (*f)(uid_t, uid_t));
360   FUNCTION(setsid, pid_t (*f)(void));
361   FUNCTION(setuid, int (*f)(uid_t));
362   FUNCTION(sleep, unsigned (*f)(unsigned));
363   FUNCTION(swab, void (*f)(const void*, void*, ssize_t));
364   FUNCTION(symlink, int (*f)(const char*, const char*));
365   FUNCTION(symlinkat, int (*f)(const char*, int, const char*));
366   FUNCTION(sync, void (*f)(void));
367   FUNCTION(sysconf, long (*f)(int));
368   FUNCTION(tcgetpgrp, pid_t (*f)(int));
369   FUNCTION(tcsetpgrp, int (*f)(int, pid_t));
370   FUNCTION(truncate, int (*f)(const char*, off_t));
371   FUNCTION(ttyname, char* (*f)(int));
372   FUNCTION(ttyname_r, int (*f)(int, char*, size_t));
373   FUNCTION(unlink, int (*f)(const char*));
374   FUNCTION(unlinkat, int (*f)(int, const char*, int));
375   FUNCTION(write, ssize_t (*f)(int, const void*, size_t));
376 
377   char* cp;
378   cp = optarg;
379   int i;
380   i = opterr;
381   i = optind;
382   i = optopt;
383 }
384