1
2
3
4
5
6
7
8#define _ALL_SOURCE
9
10#ifdef __APPLE__
11
12
13
14#define _DARWIN_C_SOURCE
15
16#define st_atim st_atimespec
17#define st_ctim st_ctimespec
18#define st_mtim st_mtimespec
19#endif
20
21
22
23#ifdef __GNUC__
24#define printf_format __attribute__((format(printf, 1, 2)))
25#else
26#define printf_format
27#endif
28
29
30#define _FILE_OFFSET_BITS 64
31
32
33
34
35
36
37
38#include <sys/types.h>
39
40
41
42#ifndef AT_FDCWD
43#define AT_FDCWD -100
44#endif
45
46#ifndef AT_SYMLINK_NOFOLLOW
47#define AT_SYMLINK_NOFOLLOW 0x100
48#endif
49
50#ifndef AT_REMOVEDIR
51#define AT_REMOVEDIR 0x200
52#endif
53
54#ifndef RLIMIT_RTTIME
55#define RLIMIT_RTTIME 15
56#endif
57
58
59#ifndef SEEK_DATA
60#define SEEK_DATA 3
61#endif
62#ifndef SEEK_HOLE
63#define SEEK_HOLE 4
64#endif
65
66
67
68
69
70
71
72
73
74
75
76#if defined(__GLIBC__)
77
78
79char *crypt(const char *key, const char *salt);
80
81
82
83#include <wchar.h>
84int wcwidth(wchar_t wc);
85
86
87#include <time.h>
88char *strptime(const char *buf, const char *format, struct tm *tm);
89
90
91
92
93
94
95
96
97
98
99char *dirname(char *path);
100char *__xpg_basename(char *path);
101static inline char *basename(char *path) { return __xpg_basename(path); }
102char *strcasestr(const char *haystack, const char *needle);
103#endif
104
105#if !defined(__GLIBC__)
106
107#include <libgen.h>
108#endif
109
110
111
112#ifdef __APPLE__
113
114#include <libkern/OSByteOrder.h>
115
116#ifdef __BIG_ENDIAN__
117#define IS_BIG_ENDIAN 1
118#else
119#define IS_BIG_ENDIAN 0
120#endif
121
122#define bswap_16(x) OSSwapInt16(x)
123#define bswap_32(x) OSSwapInt32(x)
124#define bswap_64(x) OSSwapInt64(x)
125
126int clearenv(void);
127
128#elif defined(__FreeBSD__)
129
130#include <sys/endian.h>
131
132#if _BYTE_ORDER == _BIG_ENDIAN
133#define IS_BIG_ENDIAN 1
134#else
135#define IS_BIG_ENDIAN 0
136#endif
137
138#else
139
140#include <byteswap.h>
141#include <endian.h>
142
143#if __BYTE_ORDER == __BIG_ENDIAN
144#define IS_BIG_ENDIAN 1
145#else
146#define IS_BIG_ENDIAN 0
147#endif
148
149#endif
150
151#if IS_BIG_ENDIAN
152#define IS_LITTLE_ENDIAN 0
153#define SWAP_BE16(x) (x)
154#define SWAP_BE32(x) (x)
155#define SWAP_BE64(x) (x)
156#define SWAP_LE16(x) bswap_16(x)
157#define SWAP_LE32(x) bswap_32(x)
158#define SWAP_LE64(x) bswap_64(x)
159#else
160#define IS_LITTLE_ENDIAN 1
161#define SWAP_BE16(x) bswap_16(x)
162#define SWAP_BE32(x) bswap_32(x)
163#define SWAP_BE64(x) bswap_64(x)
164#define SWAP_LE16(x) (x)
165#define SWAP_LE32(x) (x)
166#define SWAP_LE64(x) (x)
167#endif
168
169
170#include <sys/mount.h>
171#ifdef __linux__
172#include <sys/statfs.h>
173#include <sys/swap.h>
174#include <sys/sysinfo.h>
175#endif
176
177#ifdef __APPLE__
178#include <util.h>
179#elif !defined(__FreeBSD__)
180#include <pty.h>
181#else
182#include <termios.h>
183#ifndef IUTF8
184#define IUTF8 0
185#endif
186#endif
187
188#ifndef __FreeBSD__
189#include <sys/xattr.h>
190#endif
191
192
193
194#if CFG_TOYBOX_SHADOW
195#include <shadow.h>
196#endif
197#if CFG_TOYBOX_UTMPX
198#include <utmpx.h>
199#else
200struct utmpx {int ut_type;};
201#define USER_PROCESS 0
202static inline struct utmpx *getutxent(void) {return 0;}
203static inline void setutxent(void) {;}
204static inline void endutxent(void) {;}
205#endif
206
207
208#include <fcntl.h>
209#ifndef O_NOFOLLOW
210#define O_NOFOLLOW 0
211#endif
212#ifndef O_NOATIME
213#define O_NOATIME 01000000
214#endif
215#ifndef O_CLOEXEC
216#define O_CLOEXEC 02000000
217#endif
218#ifndef O_PATH
219#define O_PATH 010000000
220#endif
221#ifndef SCHED_RESET_ON_FORK
222#define SCHED_RESET_ON_FORK (1<<30)
223#endif
224
225
226
227#ifndef F_SETPIPE_SZ
228#define F_SETPIPE_SZ 1031
229#endif
230
231#ifndef F_GETPIPE_SZ
232#define F_GETPIPE_SZ 1032
233#endif
234
235#if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \
236 && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__
237typedef double FLOAT;
238#else
239typedef float FLOAT;
240#endif
241
242#ifndef __uClinux__
243pid_t xfork(void);
244#endif
245
246
247
248
249
250
251#ifdef __BIONIC__
252#include <android/log.h>
253#include <sys/system_properties.h>
254#else
255typedef enum android_LogPriority {
256 ANDROID_LOG_UNKNOWN = 0,
257 ANDROID_LOG_DEFAULT,
258 ANDROID_LOG_VERBOSE,
259 ANDROID_LOG_DEBUG,
260 ANDROID_LOG_INFO,
261 ANDROID_LOG_WARN,
262 ANDROID_LOG_ERROR,
263 ANDROID_LOG_FATAL,
264 ANDROID_LOG_SILENT,
265} android_LogPriority;
266static inline int __android_log_write(int pri, const char *tag, const char *msg)
267{
268 return -1;
269}
270#define PROP_VALUE_MAX 92
271static inline int __system_property_set(const char *key, const char *value)
272{
273 return -1;
274}
275#endif
276
277
278#if defined(__BIONIC__) && !defined(__ANDROID_NDK__)
279#include <cutils/sched_policy.h>
280#else
281static inline int get_sched_policy(int tid, void *policy) {return 0;}
282static inline char *get_sched_policy_name(int policy) {return "unknown";}
283#endif
284
285
286
287#ifdef __ANDROID_NDK__
288#define __android_log_write(a, b, c) (0)
289#define adjtime(x, y) (0)
290#endif
291
292#ifndef SYSLOG_NAMES
293typedef struct {char *c_name; int c_val;} CODE;
294extern CODE prioritynames[], facilitynames[];
295#endif
296
297#if CFG_TOYBOX_GETRANDOM
298#include <sys/random.h>
299#endif
300int xgetrandom(void *buf, unsigned len, unsigned flags);
301
302
303#ifdef __BIONIC__
304#define _CS_PATH 0
305#define _CS_V7_ENV 1
306#include <string.h>
307static inline void confstr(int a, char *b, int c) {strcpy(b, a ? "POSIXLY_CORRECT=1" : "/bin:/usr/bin");}
308#endif
309