1 | /* |
---|
2 | * stdlib.h |
---|
3 | * |
---|
4 | * Definitions for common types, variables, and functions. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _STDLIB_H_ |
---|
8 | #define _STDLIB_H_ |
---|
9 | |
---|
10 | #include <machine/ieeefp.h> |
---|
11 | #include "_ansi.h" |
---|
12 | |
---|
13 | #define __need_size_t |
---|
14 | #define __need_wchar_t |
---|
15 | #define __need_NULL |
---|
16 | #include <stddef.h> |
---|
17 | |
---|
18 | #include <sys/reent.h> |
---|
19 | #include <sys/cdefs.h> |
---|
20 | #include <machine/stdlib.h> |
---|
21 | #ifndef __STRICT_ANSI__ |
---|
22 | #include <alloca.h> |
---|
23 | #endif |
---|
24 | |
---|
25 | #ifdef __CYGWIN__ |
---|
26 | #include <cygwin/stdlib.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #if __GNU_VISIBLE |
---|
30 | #include <xlocale.h> |
---|
31 | #endif |
---|
32 | |
---|
33 | _BEGIN_STD_C |
---|
34 | |
---|
35 | typedef struct |
---|
36 | { |
---|
37 | int quot; /* quotient */ |
---|
38 | int rem; /* remainder */ |
---|
39 | } div_t; |
---|
40 | |
---|
41 | typedef struct |
---|
42 | { |
---|
43 | long quot; /* quotient */ |
---|
44 | long rem; /* remainder */ |
---|
45 | } ldiv_t; |
---|
46 | |
---|
47 | #if __ISO_C_VISIBLE >= 1999 |
---|
48 | typedef struct |
---|
49 | { |
---|
50 | long long int quot; /* quotient */ |
---|
51 | long long int rem; /* remainder */ |
---|
52 | } lldiv_t; |
---|
53 | #endif |
---|
54 | |
---|
55 | #ifndef __compar_fn_t_defined |
---|
56 | #define __compar_fn_t_defined |
---|
57 | typedef int (*__compar_fn_t) (const void *, const void *); |
---|
58 | #endif |
---|
59 | |
---|
60 | #define EXIT_FAILURE 1 |
---|
61 | #define EXIT_SUCCESS 0 |
---|
62 | |
---|
63 | #define RAND_MAX __RAND_MAX |
---|
64 | |
---|
65 | int __locale_mb_cur_max (void); |
---|
66 | |
---|
67 | #define MB_CUR_MAX __locale_mb_cur_max() |
---|
68 | |
---|
69 | void abort (void) _ATTRIBUTE ((__noreturn__)); |
---|
70 | int abs (int); |
---|
71 | #if __BSD_VISIBLE |
---|
72 | __uint32_t arc4random (void); |
---|
73 | __uint32_t arc4random_uniform (__uint32_t); |
---|
74 | void arc4random_buf (void *, size_t); |
---|
75 | #endif |
---|
76 | int atexit (void (*__func)(void)); |
---|
77 | double atof (const char *__nptr); |
---|
78 | #if __MISC_VISIBLE |
---|
79 | float atoff (const char *__nptr); |
---|
80 | #endif |
---|
81 | int atoi (const char *__nptr); |
---|
82 | int _atoi_r (struct _reent *, const char *__nptr); |
---|
83 | long atol (const char *__nptr); |
---|
84 | long _atol_r (struct _reent *, const char *__nptr); |
---|
85 | void * bsearch (const void *__key, |
---|
86 | const void *__base, |
---|
87 | size_t __nmemb, |
---|
88 | size_t __size, |
---|
89 | __compar_fn_t _compar); |
---|
90 | void * calloc (size_t __nmemb, size_t __size) _NOTHROW; |
---|
91 | div_t div (int __numer, int __denom); |
---|
92 | void exit (int __status) _ATTRIBUTE ((__noreturn__)); |
---|
93 | void free (void *) _NOTHROW; |
---|
94 | char * getenv (const char *__string); |
---|
95 | char * _getenv_r (struct _reent *, const char *__string); |
---|
96 | char * _findenv (const char *, int *); |
---|
97 | char * _findenv_r (struct _reent *, const char *, int *); |
---|
98 | #if __POSIX_VISIBLE >= 200809 |
---|
99 | extern char *suboptarg; /* getsubopt(3) external variable */ |
---|
100 | int getsubopt (char **, char * const *, char **); |
---|
101 | #endif |
---|
102 | long labs (long); |
---|
103 | ldiv_t ldiv (long __numer, long __denom); |
---|
104 | void * malloc (size_t __size) _NOTHROW; |
---|
105 | int mblen (const char *, size_t); |
---|
106 | int _mblen_r (struct _reent *, const char *, size_t, _mbstate_t *); |
---|
107 | int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); |
---|
108 | int _mbtowc_r (struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *); |
---|
109 | int wctomb (char *, wchar_t); |
---|
110 | int _wctomb_r (struct _reent *, char *, wchar_t, _mbstate_t *); |
---|
111 | size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); |
---|
112 | size_t _mbstowcs_r (struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *); |
---|
113 | size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); |
---|
114 | size_t _wcstombs_r (struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *); |
---|
115 | #ifndef _REENT_ONLY |
---|
116 | #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 |
---|
117 | char * mkdtemp (char *); |
---|
118 | #endif |
---|
119 | #if __GNU_VISIBLE |
---|
120 | int mkostemp (char *, int); |
---|
121 | int mkostemps (char *, int, int); |
---|
122 | #endif |
---|
123 | #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4 |
---|
124 | int mkstemp (char *); |
---|
125 | #endif |
---|
126 | #if __MISC_VISIBLE |
---|
127 | int mkstemps (char *, int); |
---|
128 | #endif |
---|
129 | #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112) |
---|
130 | char * mktemp (char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))); |
---|
131 | #endif |
---|
132 | #endif /* !_REENT_ONLY */ |
---|
133 | char * _mkdtemp_r (struct _reent *, char *); |
---|
134 | int _mkostemp_r (struct _reent *, char *, int); |
---|
135 | int _mkostemps_r (struct _reent *, char *, int, int); |
---|
136 | int _mkstemp_r (struct _reent *, char *); |
---|
137 | int _mkstemps_r (struct _reent *, char *, int); |
---|
138 | char * _mktemp_r (struct _reent *, char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))); |
---|
139 | void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar); |
---|
140 | int rand (void); |
---|
141 | void * realloc (void *__r, size_t __size) _NOTHROW; |
---|
142 | #if __BSD_VISIBLE |
---|
143 | void *reallocarray(void *, size_t, size_t) __result_use_check __alloc_size(2) |
---|
144 | __alloc_size(3); |
---|
145 | void * reallocf (void *__r, size_t __size); |
---|
146 | #endif |
---|
147 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 |
---|
148 | char * realpath (const char *__restrict path, char *__restrict resolved_path); |
---|
149 | #endif |
---|
150 | #if __BSD_VISIBLE |
---|
151 | int rpmatch (const char *response); |
---|
152 | #endif |
---|
153 | #if __XSI_VISIBLE |
---|
154 | void setkey (const char *__key); |
---|
155 | #endif |
---|
156 | void srand (unsigned __seed); |
---|
157 | double strtod (const char *__restrict __n, char **__restrict __end_PTR); |
---|
158 | double _strtod_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR); |
---|
159 | #if __ISO_C_VISIBLE >= 1999 |
---|
160 | float strtof (const char *__restrict __n, char **__restrict __end_PTR); |
---|
161 | #endif |
---|
162 | #if __MISC_VISIBLE |
---|
163 | /* the following strtodf interface is deprecated...use strtof instead */ |
---|
164 | # ifndef strtodf |
---|
165 | # define strtodf strtof |
---|
166 | # endif |
---|
167 | #endif |
---|
168 | long strtol (const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
169 | long _strtol_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
170 | unsigned long strtoul (const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
171 | unsigned long _strtoul_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
172 | |
---|
173 | #if __GNU_VISIBLE |
---|
174 | double strtod_l (const char *__restrict, char **__restrict, locale_t); |
---|
175 | float strtof_l (const char *__restrict, char **__restrict, locale_t); |
---|
176 | #ifdef _HAVE_LONG_DOUBLE |
---|
177 | extern long double strtold_l (const char *__restrict, char **__restrict, |
---|
178 | locale_t); |
---|
179 | #endif /* _HAVE_LONG_DOUBLE */ |
---|
180 | long strtol_l (const char *__restrict, char **__restrict, int, locale_t); |
---|
181 | unsigned long strtoul_l (const char *__restrict, char **__restrict, int, |
---|
182 | locale_t __loc); |
---|
183 | long long strtoll_l (const char *__restrict, char **__restrict, int, locale_t); |
---|
184 | unsigned long long strtoull_l (const char *__restrict, char **__restrict, int, |
---|
185 | locale_t __loc); |
---|
186 | #endif |
---|
187 | |
---|
188 | int system (const char *__string); |
---|
189 | |
---|
190 | #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 |
---|
191 | long a64l (const char *__input); |
---|
192 | char * l64a (long __input); |
---|
193 | char * _l64a_r (struct _reent *,long __input); |
---|
194 | #endif |
---|
195 | #if __MISC_VISIBLE |
---|
196 | int on_exit (void (*__func)(int, void *),void *__arg); |
---|
197 | #endif |
---|
198 | #if __ISO_C_VISIBLE >= 1999 |
---|
199 | void _Exit (int __status) _ATTRIBUTE ((__noreturn__)); |
---|
200 | #endif |
---|
201 | #if __SVID_VISIBLE || __XSI_VISIBLE |
---|
202 | int putenv (char *__string); |
---|
203 | #endif |
---|
204 | int _putenv_r (struct _reent *, char *__string); |
---|
205 | void * _reallocf_r (struct _reent *, void *, size_t); |
---|
206 | #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 |
---|
207 | int setenv (const char *__string, const char *__value, int __overwrite); |
---|
208 | #endif |
---|
209 | int _setenv_r (struct _reent *, const char *__string, const char *__value, int __overwrite); |
---|
210 | |
---|
211 | #if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112 |
---|
212 | char * gcvt (double,int,char *); |
---|
213 | char * gcvtf (float,int,char *); |
---|
214 | char * fcvt (double,int,int *,int *); |
---|
215 | char * fcvtf (float,int,int *,int *); |
---|
216 | char * ecvt (double,int,int *,int *); |
---|
217 | char * ecvtbuf (double, int, int*, int*, char *); |
---|
218 | char * fcvtbuf (double, int, int*, int*, char *); |
---|
219 | char * ecvtf (float,int,int *,int *); |
---|
220 | #endif |
---|
221 | char * __itoa (int, char *, int); |
---|
222 | char * __utoa (unsigned, char *, int); |
---|
223 | #if __MISC_VISIBLE |
---|
224 | char * itoa (int, char *, int); |
---|
225 | char * utoa (unsigned, char *, int); |
---|
226 | #endif |
---|
227 | #if __POSIX_VISIBLE |
---|
228 | int rand_r (unsigned *__seed); |
---|
229 | #endif |
---|
230 | |
---|
231 | #if __SVID_VISIBLE || __XSI_VISIBLE |
---|
232 | double drand48 (void); |
---|
233 | double _drand48_r (struct _reent *); |
---|
234 | double erand48 (unsigned short [3]); |
---|
235 | double _erand48_r (struct _reent *, unsigned short [3]); |
---|
236 | long jrand48 (unsigned short [3]); |
---|
237 | long _jrand48_r (struct _reent *, unsigned short [3]); |
---|
238 | void lcong48 (unsigned short [7]); |
---|
239 | void _lcong48_r (struct _reent *, unsigned short [7]); |
---|
240 | long lrand48 (void); |
---|
241 | long _lrand48_r (struct _reent *); |
---|
242 | long mrand48 (void); |
---|
243 | long _mrand48_r (struct _reent *); |
---|
244 | long nrand48 (unsigned short [3]); |
---|
245 | long _nrand48_r (struct _reent *, unsigned short [3]); |
---|
246 | unsigned short * |
---|
247 | seed48 (unsigned short [3]); |
---|
248 | unsigned short * |
---|
249 | _seed48_r (struct _reent *, unsigned short [3]); |
---|
250 | void srand48 (long); |
---|
251 | void _srand48_r (struct _reent *, long); |
---|
252 | #endif /* __SVID_VISIBLE || __XSI_VISIBLE */ |
---|
253 | #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE |
---|
254 | char * initstate (unsigned, char *, size_t); |
---|
255 | long random (void); |
---|
256 | char * setstate (char *); |
---|
257 | void srandom (unsigned); |
---|
258 | #endif |
---|
259 | #if __ISO_C_VISIBLE >= 1999 |
---|
260 | long long atoll (const char *__nptr); |
---|
261 | #endif |
---|
262 | long long _atoll_r (struct _reent *, const char *__nptr); |
---|
263 | #if __ISO_C_VISIBLE >= 1999 |
---|
264 | long long llabs (long long); |
---|
265 | lldiv_t lldiv (long long __numer, long long __denom); |
---|
266 | long long strtoll (const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
267 | #endif |
---|
268 | long long _strtoll_r (struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
269 | #if __ISO_C_VISIBLE >= 1999 |
---|
270 | unsigned long long strtoull (const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
271 | #endif |
---|
272 | unsigned long long _strtoull_r (struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base); |
---|
273 | |
---|
274 | #ifndef __CYGWIN__ |
---|
275 | #if __MISC_VISIBLE |
---|
276 | void cfree (void *); |
---|
277 | #endif |
---|
278 | #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 |
---|
279 | int unsetenv (const char *__string); |
---|
280 | #endif |
---|
281 | int _unsetenv_r (struct _reent *, const char *__string); |
---|
282 | #endif /* !__CYGWIN__ */ |
---|
283 | |
---|
284 | #if __POSIX_VISIBLE >= 200112 |
---|
285 | int __nonnull ((1)) posix_memalign (void **, size_t, size_t); |
---|
286 | #endif |
---|
287 | |
---|
288 | char * _dtoa_r (struct _reent *, double, int, int, int *, int*, char**); |
---|
289 | #ifndef __CYGWIN__ |
---|
290 | void * _malloc_r (struct _reent *, size_t) _NOTHROW; |
---|
291 | void * _calloc_r (struct _reent *, size_t, size_t) _NOTHROW; |
---|
292 | void _free_r (struct _reent *, void *) _NOTHROW; |
---|
293 | void * _realloc_r (struct _reent *, void *, size_t) _NOTHROW; |
---|
294 | void _mstats_r (struct _reent *, char *); |
---|
295 | #endif |
---|
296 | int _system_r (struct _reent *, const char *); |
---|
297 | |
---|
298 | void __eprintf (const char *, const char *, unsigned int, const char *); |
---|
299 | |
---|
300 | /* There are two common qsort_r variants. If you request |
---|
301 | _BSD_SOURCE, you get the BSD version; otherwise you get the GNU |
---|
302 | version. We want that #undef qsort_r will still let you |
---|
303 | invoke the underlying function, but that requires gcc support. */ |
---|
304 | #if __GNU_VISIBLE |
---|
305 | void qsort_r (void *__base, size_t __nmemb, size_t __size, int (*_compar)(const void *, const void *, void *), void *__thunk); |
---|
306 | #elif __BSD_VISIBLE |
---|
307 | # ifdef __GNUC__ |
---|
308 | void qsort_r (void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *)) |
---|
309 | __asm__ (__ASMNAME ("__bsd_qsort_r")); |
---|
310 | # else |
---|
311 | void __bsd_qsort_r (void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *)); |
---|
312 | # define qsort_r __bsd_qsort_r |
---|
313 | # endif |
---|
314 | #endif |
---|
315 | |
---|
316 | /* On platforms where long double equals double. */ |
---|
317 | #ifdef _HAVE_LONG_DOUBLE |
---|
318 | extern long double _strtold_r (struct _reent *, const char *__restrict, char **__restrict); |
---|
319 | #if __ISO_C_VISIBLE >= 1999 |
---|
320 | extern long double strtold (const char *__restrict, char **__restrict); |
---|
321 | #endif |
---|
322 | #endif /* _HAVE_LONG_DOUBLE */ |
---|
323 | |
---|
324 | /* |
---|
325 | * If we're in a mode greater than C99, expose C11 functions. |
---|
326 | */ |
---|
327 | #if __ISO_C_VISIBLE >= 2011 |
---|
328 | void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1) |
---|
329 | __alloc_size(2); |
---|
330 | int at_quick_exit(void (*)(void)); |
---|
331 | _Noreturn void |
---|
332 | quick_exit(int); |
---|
333 | #endif /* __ISO_C_VISIBLE >= 2011 */ |
---|
334 | |
---|
335 | _END_STD_C |
---|
336 | |
---|
337 | #if __SSP_FORTIFY_LEVEL > 0 |
---|
338 | #include <ssp/stdlib.h> |
---|
339 | #endif |
---|
340 | |
---|
341 | #endif /* _STDLIB_H_ */ |
---|