1
2
3
4
5
6
7
8#define _ALL_SOURCE
9
10
11
12#ifdef __GNUC__
13#define noreturn __attribute__((noreturn))
14#define printf_format __attribute__((format(printf, 1, 2)))
15#else
16#define noreturn
17#define printf_format
18#endif
19
20
21#define _FILE_OFFSET_BITS 64
22
23
24
25#include <features.h>
26
27
28#include <sys/types.h>
29
30
31
32#ifndef AT_FDCWD
33#define AT_FDCWD -100
34#endif
35
36#ifndef AT_SYMLINK_NOFOLLOW
37#define AT_SYMLINK_NOFOLLOW 0x100
38#endif
39
40#ifndef AT_REMOVEDIR
41#define AT_REMOVEDIR 0x200
42#endif
43
44#ifndef RLIMIT_RTTIME
45#define RLIMIT_RTTIME 15
46#endif
47
48
49#ifndef SEEK_DATA
50#define SEEK_DATA 3
51#endif
52#ifndef SEEK_HOLE
53#define SEEK_HOLE 4
54#endif
55
56
57
58
59
60
61
62
63
64
65
66#if defined(__GLIBC__)
67
68
69char *crypt(const char *key, const char *salt);
70
71
72
73#include <wchar.h>
74int wcwidth(wchar_t wc);
75
76
77#include <time.h>
78char *strptime(const char *buf, const char *format, struct tm *tm);
79
80
81
82
83
84
85
86
87
88
89char *dirname(char *path);
90char *__xpg_basename(char *path);
91static inline char *basename(char *path) { return __xpg_basename(path); }
92
93
94#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 10
95#define fstatat fstatat64
96int fstatat64(int dirfd, const char *pathname, void *buf, int flags);
97int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
98char *stpcpy(char *dest, const char *src);
99#include <sys/stat.h>
100int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
101int openat(int dirfd, const char *pathname, int flags, ...);
102#include <dirent.h>
103DIR *fdopendir(int fd);
104#include <unistd.h>
105int fchownat(int dirfd, const char *pathname,
106 uid_t owner, gid_t group, int flags);
107int isblank(int c);
108int unlinkat(int dirfd, const char *pathname, int flags);
109#include <stdio.h>
110ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
111
112
113
114int faccessat(int fd, const char *path, int amode, int flag);
115int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag);
116int mkdirat(int fd, const char *path, mode_t mode);
117int symlinkat(const char *path1, int fd, const char *path2);
118int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
119#include <sys/time.h>
120int futimens(int fd, const struct timespec times[2]);
121int utimensat(int fd, const char *path, const struct timespec times[2], int flag);
122
123#ifndef MNT_DETACH
124#define MNT_DETACH 2
125#endif
126#endif
127
128#endif
129
130#if !defined(__GLIBC__)
131
132#include <libgen.h>
133#endif
134
135
136
137#ifndef __APPLE__
138#include <byteswap.h>
139#include <endian.h>
140
141#if __BYTE_ORDER == __BIG_ENDIAN
142#define IS_BIG_ENDIAN 1
143#else
144#define IS_BIG_ENDIAN 0
145#endif
146
147int clearenv(void);
148#else
149
150#ifdef __BIG_ENDIAN__
151#define IS_BIG_ENDIAN 1
152#else
153#define IS_BIG_ENDIAN 0
154#endif
155
156#endif
157
158#if IS_BIG_ENDIAN
159#define IS_LITTLE_ENDIAN 0
160#define SWAP_BE16(x) (x)
161#define SWAP_BE32(x) (x)
162#define SWAP_BE64(x) (x)
163#define SWAP_LE16(x) bswap_16(x)
164#define SWAP_LE32(x) bswap_32(x)
165#define SWAP_LE64(x) bswap_64(x)
166#else
167#define IS_LITTLE_ENDIAN 1
168#define SWAP_BE16(x) bswap_16(x)
169#define SWAP_BE32(x) bswap_32(x)
170#define SWAP_BE64(x) bswap_64(x)
171#define SWAP_LE16(x) (x)
172#define SWAP_LE32(x) (x)
173#define SWAP_LE64(x) (x)
174#endif
175
176#if defined(__APPLE__) \
177 || (defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 10)
178ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
179ssize_t getline(char **lineptr, size_t *n, FILE *stream);
180#endif
181
182
183#include <sys/mount.h>
184#include <sys/swap.h>
185
186
187
188#if CFG_TOYBOX_SHADOW
189#include <shadow.h>
190#endif
191#if CFG_TOYBOX_UTMPX
192#include <utmpx.h>
193#else
194struct utmpx {int ut_type;};
195#define USER_PROCESS 0
196static inline struct utmpx *getutxent(void) {return 0;}
197static inline void setutxent(void) {;}
198static inline void endutxent(void) {;}
199#endif
200
201
202#include <fcntl.h>
203#ifndef O_NOFOLLOW
204#define O_NOFOLLOW 0
205#endif
206#ifndef O_NOATIME
207#define O_NOATIME 01000000
208#endif
209#ifndef O_CLOEXEC
210#define O_CLOEXEC 02000000
211#endif
212#ifndef O_PATH
213#define O_PATH 010000000
214#endif
215#ifndef SCHED_RESET_ON_FORK
216#define SCHED_RESET_ON_FORK (1<<30)
217#endif
218
219
220
221#ifndef F_SETPIPE_SZ
222#define F_SETPIPE_SZ 1031
223#endif
224
225#ifndef F_GETPIPE_SZ
226#define F_GETPIPE_SZ 1032
227#endif
228
229#if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \
230 && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__
231typedef double FLOAT;
232#else
233typedef float FLOAT;
234#endif
235
236#ifndef __uClinux__
237pid_t xfork(void);
238#endif
239
240
241
242
243#if CFG_TOYBOX_ANDROID_SCHEDPOLICY
244#include <cutils/sched_policy.h>
245#else
246static inline int get_sched_policy(int tid, void *policy) {return 0;}
247static inline char *get_sched_policy_name(int policy) {return "unknown";}
248#endif
249
250#ifndef SYSLOG_NAMES
251typedef struct {char *c_name; int c_val;} CODE;
252extern CODE prioritynames[], facilitynames[];
253#endif
254