1 | /* |
2 | * Copyright (c) 2000, 2002 - 2008 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ |
5 | * |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License |
8 | * Version 2.0 (the 'License'). You may not use this file except in |
9 | * compliance with the License. Please obtain a copy of the License at |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this |
11 | * file. |
12 | * |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and |
19 | * limitations under the License. |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ |
23 | /*- |
24 | * Copyright (c) 1990, 1993 |
25 | * The Regents of the University of California. All rights reserved. |
26 | * |
27 | * Redistribution and use in source and binary forms, with or without |
28 | * modification, are permitted provided that the following conditions |
29 | * are met: |
30 | * 1. Redistributions of source code must retain the above copyright |
31 | * notice, this list of conditions and the following disclaimer. |
32 | * 2. Redistributions in binary form must reproduce the above copyright |
33 | * notice, this list of conditions and the following disclaimer in the |
34 | * documentation and/or other materials provided with the distribution. |
35 | * 3. All advertising materials mentioning features or use of this software |
36 | * must display the following acknowledgement: |
37 | * This product includes software developed by the University of |
38 | * California, Berkeley and its contributors. |
39 | * 4. Neither the name of the University nor the names of its contributors |
40 | * may be used to endorse or promote products derived from this software |
41 | * without specific prior written permission. |
42 | * |
43 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
44 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
46 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
49 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
50 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
51 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
52 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
53 | * SUCH DAMAGE. |
54 | * |
55 | * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 |
56 | */ |
57 | |
58 | #ifndef _STDLIB_H_ |
59 | #define _STDLIB_H_ |
60 | |
61 | #include <Availability.h> |
62 | #include <sys/cdefs.h> |
63 | |
64 | #include <_types.h> |
65 | #if !defined(_ANSI_SOURCE) |
66 | #include <sys/wait.h> |
67 | #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
68 | #include <alloca.h> |
69 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
70 | #endif /* !_ANSI_SOURCE */ |
71 | |
72 | /* DO NOT REMOVE THIS COMMENT: fixincludes needs to see: |
73 | * _GCC_SIZE_T */ |
74 | #include <sys/_types/_size_t.h> |
75 | |
76 | #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
77 | #include <sys/_types/_ct_rune_t.h> |
78 | #include <sys/_types/_rune_t.h> |
79 | #endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
80 | |
81 | #include <sys/_types/_wchar_t.h> |
82 | |
83 | typedef struct { |
84 | int quot; /* quotient */ |
85 | int rem; /* remainder */ |
86 | } div_t; |
87 | |
88 | typedef struct { |
89 | long quot; /* quotient */ |
90 | long rem; /* remainder */ |
91 | } ldiv_t; |
92 | |
93 | #if !__DARWIN_NO_LONG_LONG |
94 | typedef struct { |
95 | long long quot; |
96 | long long rem; |
97 | } lldiv_t; |
98 | #endif /* !__DARWIN_NO_LONG_LONG */ |
99 | |
100 | #include <sys/_types/_null.h> |
101 | |
102 | #define EXIT_FAILURE 1 |
103 | #define EXIT_SUCCESS 0 |
104 | |
105 | #define RAND_MAX 0x7fffffff |
106 | |
107 | #ifdef _USE_EXTENDED_LOCALES_ |
108 | #include <_xlocale.h> |
109 | #endif /* _USE_EXTENDED_LOCALES_ */ |
110 | |
111 | #ifndef MB_CUR_MAX |
112 | #ifdef _USE_EXTENDED_LOCALES_ |
113 | #define MB_CUR_MAX (___mb_cur_max()) |
114 | #ifndef MB_CUR_MAX_L |
115 | #define MB_CUR_MAX_L(x) (___mb_cur_max_l(x)) |
116 | #endif /* !MB_CUR_MAX_L */ |
117 | #else /* !_USE_EXTENDED_LOCALES_ */ |
118 | extern int __mb_cur_max; |
119 | #define MB_CUR_MAX __mb_cur_max |
120 | #endif /* _USE_EXTENDED_LOCALES_ */ |
121 | #endif /* MB_CUR_MAX */ |
122 | |
123 | #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) \ |
124 | && defined(_USE_EXTENDED_LOCALES_) && !defined(MB_CUR_MAX_L) |
125 | #define MB_CUR_MAX_L(x) (___mb_cur_max_l(x)) |
126 | #endif |
127 | |
128 | #include <malloc/_malloc.h> |
129 | |
130 | __BEGIN_DECLS |
131 | void abort(void) __dead2; |
132 | int abs(int) __pure2; |
133 | int atexit(void (* _Nonnull)(void)); |
134 | double atof(const char *); |
135 | int atoi(const char *); |
136 | long atol(const char *); |
137 | #if !__DARWIN_NO_LONG_LONG |
138 | long long |
139 | atoll(const char *); |
140 | #endif /* !__DARWIN_NO_LONG_LONG */ |
141 | void *bsearch(const void *__key, const void *__base, size_t __nel, |
142 | size_t __width, int (* _Nonnull __compar)(const void *, const void *)); |
143 | /* calloc is now declared in _malloc.h */ |
144 | div_t div(int, int) __pure2; |
145 | void exit(int) __dead2; |
146 | /* free is now declared in _malloc.h */ |
147 | char *getenv(const char *); |
148 | long labs(long) __pure2; |
149 | ldiv_t ldiv(long, long) __pure2; |
150 | #if !__DARWIN_NO_LONG_LONG |
151 | long long |
152 | llabs(long long); |
153 | lldiv_t lldiv(long long, long long); |
154 | #endif /* !__DARWIN_NO_LONG_LONG */ |
155 | /* malloc is now declared in _malloc.h */ |
156 | int mblen(const char *__s, size_t __n); |
157 | size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); |
158 | int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); |
159 | /* posix_memalign is now declared in _malloc.h */ |
160 | void qsort(void *__base, size_t __nel, size_t __width, |
161 | int (* _Nonnull __compar)(const void *, const void *)); |
162 | int rand(void) __swift_unavailable("Use arc4random instead." ); |
163 | /* realloc is now declared in _malloc.h */ |
164 | void srand(unsigned) __swift_unavailable("Use arc4random instead." ); |
165 | double strtod(const char *, char **) __DARWIN_ALIAS(strtod); |
166 | float strtof(const char *, char **) __DARWIN_ALIAS(strtof); |
167 | long strtol(const char *__str, char **__endptr, int __base); |
168 | long double |
169 | strtold(const char *, char **); |
170 | #if !__DARWIN_NO_LONG_LONG |
171 | long long |
172 | strtoll(const char *__str, char **__endptr, int __base); |
173 | #endif /* !__DARWIN_NO_LONG_LONG */ |
174 | unsigned long |
175 | strtoul(const char *__str, char **__endptr, int __base); |
176 | #if !__DARWIN_NO_LONG_LONG |
177 | unsigned long long |
178 | strtoull(const char *__str, char **__endptr, int __base); |
179 | #endif /* !__DARWIN_NO_LONG_LONG */ |
180 | |
181 | #if TARGET_OS_EMBEDDED |
182 | #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(ios_msg) |
183 | #else |
184 | #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(osx_msg) |
185 | #endif |
186 | |
187 | __swift_unavailable_on("Use posix_spawn APIs or NSTask instead." , "Process spawning is unavailable" ) |
188 | __API_AVAILABLE(macos(10.0)) __IOS_PROHIBITED |
189 | __WATCHOS_PROHIBITED __TVOS_PROHIBITED |
190 | int system(const char *) __DARWIN_ALIAS_C(system); |
191 | |
192 | #undef __swift_unavailable_on |
193 | |
194 | size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); |
195 | int wctomb(char *, wchar_t); |
196 | |
197 | #ifndef _ANSI_SOURCE |
198 | void _Exit(int) __dead2; |
199 | long a64l(const char *); |
200 | double drand48(void); |
201 | char *ecvt(double, int, int *__restrict, int *__restrict); /* LEGACY */ |
202 | double erand48(unsigned short[3]); |
203 | char *fcvt(double, int, int *__restrict, int *__restrict); /* LEGACY */ |
204 | char *gcvt(double, int, char *); /* LEGACY */ |
205 | int getsubopt(char **, char * const *, char **); |
206 | int grantpt(int); |
207 | #if __DARWIN_UNIX03 |
208 | char *initstate(unsigned, char *, size_t); /* no __DARWIN_ALIAS needed */ |
209 | #else /* !__DARWIN_UNIX03 */ |
210 | char *initstate(unsigned long, char *, long); |
211 | #endif /* __DARWIN_UNIX03 */ |
212 | long jrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead." ); |
213 | char *l64a(long); |
214 | void lcong48(unsigned short[7]); |
215 | long lrand48(void) __swift_unavailable("Use arc4random instead." ); |
216 | char *mktemp(char *); |
217 | int mkstemp(char *); |
218 | long mrand48(void) __swift_unavailable("Use arc4random instead." ); |
219 | long nrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead." ); |
220 | int posix_openpt(int); |
221 | char *ptsname(int); |
222 | |
223 | #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
224 | int ptsname_r(int fildes, char *buffer, size_t buflen) __API_AVAILABLE(macos(10.13.4), ios(11.3), tvos(11.3), watchos(4.3)); |
225 | #endif |
226 | |
227 | int putenv(char *) __DARWIN_ALIAS(putenv); |
228 | long random(void) __swift_unavailable("Use arc4random instead." ); |
229 | int rand_r(unsigned *) __swift_unavailable("Use arc4random instead." ); |
230 | #if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH) |
231 | char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath); |
232 | #else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */ |
233 | char *realpath(const char * __restrict, char * __restrict) __DARWIN_ALIAS(realpath); |
234 | #endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */ |
235 | unsigned short |
236 | *seed48(unsigned short[3]); |
237 | int setenv(const char * __name, const char * __value, int __overwrite) __DARWIN_ALIAS(setenv); |
238 | #if __DARWIN_UNIX03 |
239 | void setkey(const char *) __DARWIN_ALIAS(setkey); |
240 | #else /* !__DARWIN_UNIX03 */ |
241 | int setkey(const char *); |
242 | #endif /* __DARWIN_UNIX03 */ |
243 | char *setstate(const char *); |
244 | void srand48(long); |
245 | #if __DARWIN_UNIX03 |
246 | void srandom(unsigned); |
247 | #else /* !__DARWIN_UNIX03 */ |
248 | void srandom(unsigned long); |
249 | #endif /* __DARWIN_UNIX03 */ |
250 | int unlockpt(int); |
251 | #if __DARWIN_UNIX03 |
252 | int unsetenv(const char *) __DARWIN_ALIAS(unsetenv); |
253 | #else /* !__DARWIN_UNIX03 */ |
254 | void unsetenv(const char *); |
255 | #endif /* __DARWIN_UNIX03 */ |
256 | #endif /* !_ANSI_SOURCE */ |
257 | |
258 | #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
259 | #include <machine/types.h> |
260 | |
261 | #include <sys/_types/_dev_t.h> |
262 | #include <sys/_types/_mode_t.h> |
263 | #include <_types/_uint32_t.h> |
264 | |
265 | uint32_t arc4random(void); |
266 | void arc4random_addrandom(unsigned char * /*dat*/, int /*datlen*/) |
267 | __OSX_DEPRECATED(10.0, 10.12, "use arc4random_stir" ) |
268 | __IOS_DEPRECATED(2.0, 10.0, "use arc4random_stir" ) |
269 | __TVOS_DEPRECATED(2.0, 10.0, "use arc4random_stir" ) |
270 | __WATCHOS_DEPRECATED(1.0, 3.0, "use arc4random_stir" ); |
271 | void arc4random_buf(void * __buf, size_t __nbytes) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
272 | void arc4random_stir(void); |
273 | uint32_t |
274 | arc4random_uniform(uint32_t __upper_bound) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
275 | #ifdef __BLOCKS__ |
276 | int atexit_b(void (^ _Nonnull)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
277 | void *bsearch_b(const void *__key, const void *__base, size_t __nel, |
278 | size_t __width, int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
279 | #endif /* __BLOCKS__ */ |
280 | |
281 | /* getcap(3) functions */ |
282 | char *cgetcap(char *, const char *, int); |
283 | int cgetclose(void); |
284 | int cgetent(char **, char **, const char *); |
285 | int cgetfirst(char **, char **); |
286 | int cgetmatch(const char *, const char *); |
287 | int cgetnext(char **, char **); |
288 | int cgetnum(char *, const char *, long *); |
289 | int cgetset(const char *); |
290 | int cgetstr(char *, const char *, char **); |
291 | int cgetustr(char *, const char *, char **); |
292 | |
293 | int daemon(int, int) __DARWIN_1050(daemon) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_0, __MAC_10_5, __IPHONE_2_0, __IPHONE_2_0, "Use posix_spawn APIs instead." ) __WATCHOS_PROHIBITED __TVOS_PROHIBITED; |
294 | char *devname(dev_t, mode_t); |
295 | char *devname_r(dev_t, mode_t, char *buf, int len); |
296 | char *getbsize(int *, long *); |
297 | int getloadavg(double [], int); |
298 | const char |
299 | *getprogname(void); |
300 | |
301 | int heapsort(void *__base, size_t __nel, size_t __width, |
302 | int (* _Nonnull __compar)(const void *, const void *)); |
303 | #ifdef __BLOCKS__ |
304 | int heapsort_b(void *__base, size_t __nel, size_t __width, |
305 | int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
306 | #endif /* __BLOCKS__ */ |
307 | int mergesort(void *__base, size_t __nel, size_t __width, |
308 | int (* _Nonnull __compar)(const void *, const void *)); |
309 | #ifdef __BLOCKS__ |
310 | int mergesort_b(void *__base, size_t __nel, size_t __width, |
311 | int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
312 | #endif /* __BLOCKS__ */ |
313 | void psort(void *__base, size_t __nel, size_t __width, |
314 | int (* _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
315 | #ifdef __BLOCKS__ |
316 | void psort_b(void *__base, size_t __nel, size_t __width, |
317 | int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
318 | #endif /* __BLOCKS__ */ |
319 | void psort_r(void *__base, size_t __nel, size_t __width, void *, |
320 | int (* _Nonnull __compar)(void *, const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
321 | #ifdef __BLOCKS__ |
322 | void qsort_b(void *__base, size_t __nel, size_t __width, |
323 | int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); |
324 | #endif /* __BLOCKS__ */ |
325 | void qsort_r(void *__base, size_t __nel, size_t __width, void *, |
326 | int (* _Nonnull __compar)(void *, const void *, const void *)); |
327 | int radixsort(const unsigned char **__base, int __nel, const unsigned char *__table, |
328 | unsigned __endbyte); |
329 | void setprogname(const char *); |
330 | int sradixsort(const unsigned char **__base, int __nel, const unsigned char *__table, |
331 | unsigned __endbyte); |
332 | void sranddev(void); |
333 | void srandomdev(void); |
334 | void *reallocf(void *__ptr, size_t __size) __alloc_size(2); |
335 | #if !__DARWIN_NO_LONG_LONG |
336 | long long |
337 | strtoq(const char *__str, char **__endptr, int __base); |
338 | unsigned long long |
339 | strtouq(const char *__str, char **__endptr, int __base); |
340 | #endif /* !__DARWIN_NO_LONG_LONG */ |
341 | extern char *suboptarg; /* getsubopt(3) external variable */ |
342 | /* valloc is now declared in _malloc.h */ |
343 | #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ |
344 | |
345 | /* Poison the following routines if -fshort-wchar is set */ |
346 | #if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU |
347 | #pragma GCC poison mbstowcs mbtowc wcstombs wctomb |
348 | #endif |
349 | __END_DECLS |
350 | |
351 | #ifdef _USE_EXTENDED_LOCALES_ |
352 | #include <xlocale/_stdlib.h> |
353 | #endif /* _USE_EXTENDED_LOCALES_ */ |
354 | |
355 | #endif /* _STDLIB_H_ */ |
356 | |