]> git.saurik.com Git - apple/libc.git/blob - include/stdlib.h
Libc-1244.50.9.tar.gz
[apple/libc.git] / include / stdlib.h
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
63 #include <_types.h>
64 #if !defined(_ANSI_SOURCE)
65 #include <sys/wait.h>
66 #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
67 #include <alloca.h>
68 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
69 #endif /* !_ANSI_SOURCE */
70
71 /* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
72 * _GCC_SIZE_T */
73 #include <sys/_types/_size_t.h>
74
75 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
76 #include <sys/_types/_ct_rune_t.h>
77 #include <sys/_types/_rune_t.h>
78 #endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
79
80 #include <sys/_types/_wchar_t.h>
81
82 typedef struct {
83 int quot; /* quotient */
84 int rem; /* remainder */
85 } div_t;
86
87 typedef struct {
88 long quot; /* quotient */
89 long rem; /* remainder */
90 } ldiv_t;
91
92 #if !__DARWIN_NO_LONG_LONG
93 typedef struct {
94 long long quot;
95 long long rem;
96 } lldiv_t;
97 #endif /* !__DARWIN_NO_LONG_LONG */
98
99 #include <sys/_types/_null.h>
100
101 #define EXIT_FAILURE 1
102 #define EXIT_SUCCESS 0
103
104 #define RAND_MAX 0x7fffffff
105
106 #ifdef _USE_EXTENDED_LOCALES_
107 #include <_xlocale.h>
108 #endif /* _USE_EXTENDED_LOCALES_ */
109
110 #ifndef MB_CUR_MAX
111 #ifdef _USE_EXTENDED_LOCALES_
112 #define MB_CUR_MAX (___mb_cur_max())
113 #ifndef MB_CUR_MAX_L
114 #define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
115 #endif /* !MB_CUR_MAX_L */
116 #else /* !_USE_EXTENDED_LOCALES_ */
117 extern int __mb_cur_max;
118 #define MB_CUR_MAX __mb_cur_max
119 #endif /* _USE_EXTENDED_LOCALES_ */
120 #endif /* MB_CUR_MAX */
121
122 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) \
123 && defined(_USE_EXTENDED_LOCALES_) && !defined(MB_CUR_MAX_L)
124 #define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
125 #endif
126 //Begin-Libc
127 #include "libc_private.h"
128 /* f must be a literal string */
129 #define LIBC_ABORT(f,...) abort_report_np("%s:%s:%u: " f, __FILE__, __func__, __LINE__, ## __VA_ARGS__)
130 //End-Libc
131
132 #ifndef __alloc_size
133 #if __has_attribute(alloc_size)
134 #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
135 #else
136 #define __alloc_size(...)
137 #endif
138 #endif // __alloc_size
139
140 __BEGIN_DECLS
141 void abort(void) __dead2;
142 int abs(int) __pure2;
143 int atexit(void (* _Nonnull)(void));
144 double atof(const char *);
145 int atoi(const char *);
146 long atol(const char *);
147 #if !__DARWIN_NO_LONG_LONG
148 long long
149 atoll(const char *);
150 #endif /* !__DARWIN_NO_LONG_LONG */
151 void *bsearch(const void *__key, const void *__base, size_t __nel,
152 size_t __width, int (* _Nonnull __compar)(const void *, const void *));
153 void *calloc(size_t __count, size_t __size) __result_use_check __alloc_size(1,2);
154 div_t div(int, int) __pure2;
155 void exit(int) __dead2;
156 void free(void *);
157 char *getenv(const char *);
158 long labs(long) __pure2;
159 ldiv_t ldiv(long, long) __pure2;
160 #if !__DARWIN_NO_LONG_LONG
161 long long
162 llabs(long long);
163 lldiv_t lldiv(long long, long long);
164 #endif /* !__DARWIN_NO_LONG_LONG */
165 void *malloc(size_t __size) __result_use_check __alloc_size(1);
166 int mblen(const char *__s, size_t __n);
167 size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
168 int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
169 int posix_memalign(void **__memptr, size_t __alignment, size_t __size) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0);
170 void qsort(void *__base, size_t __nel, size_t __width,
171 int (* _Nonnull __compar)(const void *, const void *));
172 int rand(void) __swift_unavailable("Use arc4random instead.");
173 void *realloc(void *__ptr, size_t __size) __result_use_check __alloc_size(2);
174 void srand(unsigned) __swift_unavailable("Use arc4random instead.");
175 double strtod(const char *, char **) __DARWIN_ALIAS(strtod);
176 float strtof(const char *, char **) __DARWIN_ALIAS(strtof);
177 long strtol(const char *__str, char **__endptr, int __base);
178 long double
179 strtold(const char *, char **);
180 #if !__DARWIN_NO_LONG_LONG
181 long long
182 strtoll(const char *__str, char **__endptr, int __base);
183 #endif /* !__DARWIN_NO_LONG_LONG */
184 unsigned long
185 strtoul(const char *__str, char **__endptr, int __base);
186 #if !__DARWIN_NO_LONG_LONG
187 unsigned long long
188 strtoull(const char *__str, char **__endptr, int __base);
189 #endif /* !__DARWIN_NO_LONG_LONG */
190 //Begin-Libc
191 #ifndef LIBC_ALIAS_SYSTEM
192 //End-Libc
193
194 #if TARGET_OS_EMBEDDED
195 #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(ios_msg)
196 #else
197 #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(osx_msg)
198 #endif
199
200 __swift_unavailable_on("Use posix_spawn APIs or NSTask instead.", "Process spawning is unavailable")
201 __API_AVAILABLE(macos(10.0)) __IOS_PROHIBITED
202 __WATCHOS_PROHIBITED __TVOS_PROHIBITED
203 int system(const char *) __DARWIN_ALIAS_C(system);
204 //Begin-Libc
205 #else /* LIBC_ALIAS_SYSTEM */
206 int system(const char *) LIBC_ALIAS_C(system);
207 #endif /* !LIBC_ALIAS_SYSTEM */
208 //End-Libc
209
210 #undef __swift_unavailable_on
211
212 size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
213 int wctomb(char *, wchar_t);
214
215 #ifndef _ANSI_SOURCE
216 void _Exit(int) __dead2;
217 long a64l(const char *);
218 double drand48(void);
219 char *ecvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
220 double erand48(unsigned short[3]);
221 char *fcvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
222 char *gcvt(double, int, char *); /* LEGACY */
223 int getsubopt(char **, char * const *, char **);
224 int grantpt(int);
225 #if __DARWIN_UNIX03
226 char *initstate(unsigned, char *, size_t); /* no __DARWIN_ALIAS needed */
227 #else /* !__DARWIN_UNIX03 */
228 char *initstate(unsigned long, char *, long);
229 #endif /* __DARWIN_UNIX03 */
230 long jrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead.");
231 char *l64a(long);
232 void lcong48(unsigned short[7]);
233 long lrand48(void) __swift_unavailable("Use arc4random instead.");
234 char *mktemp(char *);
235 int mkstemp(char *);
236 long mrand48(void) __swift_unavailable("Use arc4random instead.");
237 long nrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead.");
238 int posix_openpt(int);
239 char *ptsname(int);
240
241 #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
242 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));
243 #endif
244
245 //Begin-Libc
246 #ifndef LIBC_ALIAS_PUTENV
247 //End-Libc
248 int putenv(char *) __DARWIN_ALIAS(putenv);
249 //Begin-Libc
250 #else /* LIBC_ALIAS_PUTENV */
251 int putenv(char *) LIBC_ALIAS(putenv);
252 #endif /* !LIBC_ALIAS_PUTENV */
253 //End-Libc
254 long random(void) __swift_unavailable("Use arc4random instead.");
255 int rand_r(unsigned *) __swift_unavailable("Use arc4random instead.");
256 //Begin-Libc
257 #ifdef __LIBC__
258 #ifndef LIBC_ALIAS_REALPATH
259 char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
260 #else /* LIBC_ALIAS_REALPATH */
261 #ifdef VARIANT_DARWINEXTSN
262 char *realpath(const char * __restrict, char * __restrict) LIBC_EXTSN(realpath);
263 #else /* !VARIANT_DARWINEXTSN */
264 char *realpath(const char * __restrict, char * __restrict) LIBC_ALIAS(realpath);
265 #endif /* VARIANT_DARWINEXTSN */
266 #endif /* !LIBC_ALIAS_REALPATH */
267 #else /* !__LIBC__ */
268 //End-Libc
269 #if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
270 char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
271 #else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */
272 char *realpath(const char * __restrict, char * __restrict) __DARWIN_ALIAS(realpath);
273 #endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */
274 //Begin-Libc
275 #endif /* __LIBC__ */
276 //End-Libc
277 unsigned short
278 *seed48(unsigned short[3]);
279 //Begin-Libc
280 #ifndef LIBC_ALIAS_SETENV
281 //End-Libc
282 int setenv(const char * __name, const char * __value, int __overwrite) __DARWIN_ALIAS(setenv);
283 //Begin-Libc
284 #else /* LIBC_ALIAS_SETENV */
285 int setenv(const char * __name, const char * __value, int __overwrite) LIBC_ALIAS(setenv);
286 #endif /* !LIBC_ALIAS_SETENV */
287 //End-Libc
288 #if __DARWIN_UNIX03
289 //Begin-Libc
290 #ifndef LIBC_ALIAS_SETKEY
291 //End-Libc
292 void setkey(const char *) __DARWIN_ALIAS(setkey);
293 //Begin-Libc
294 #else /* LIBC_ALIAS_SETKEY */
295 void setkey(const char *) LIBC_ALIAS(setkey);
296 #endif /* !LIBC_ALIAS_SETKEY */
297 //End-Libc
298 #else /* !__DARWIN_UNIX03 */
299 int setkey(const char *);
300 #endif /* __DARWIN_UNIX03 */
301 char *setstate(const char *);
302 void srand48(long);
303 #if __DARWIN_UNIX03
304 void srandom(unsigned);
305 #else /* !__DARWIN_UNIX03 */
306 void srandom(unsigned long);
307 #endif /* __DARWIN_UNIX03 */
308 int unlockpt(int);
309 #if __DARWIN_UNIX03
310 //Begin-Libc
311 #ifndef LIBC_ALIAS_UNSETENV
312 //End-Libc
313 int unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
314 //Begin-Libc
315 #else /* LIBC_ALIAS_UNSETENV */
316 int unsetenv(const char *) LIBC_ALIAS(unsetenv);
317 #endif /* !LIBC_ALIAS_UNSETENV */
318 //End-Libc
319 #else /* !__DARWIN_UNIX03 */
320 void unsetenv(const char *);
321 #endif /* __DARWIN_UNIX03 */
322 #endif /* !_ANSI_SOURCE */
323
324 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
325 #include <machine/types.h>
326
327 #include <sys/_types/_dev_t.h>
328 #include <sys/_types/_mode_t.h>
329 #include <_types/_uint32_t.h>
330
331 uint32_t arc4random(void);
332 void arc4random_addrandom(unsigned char * /*dat*/, int /*datlen*/)
333 __OSX_DEPRECATED(10.0, 10.12, "use arc4random_stir")
334 __IOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
335 __TVOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
336 __WATCHOS_DEPRECATED(1.0, 3.0, "use arc4random_stir");
337 void arc4random_buf(void * __buf, size_t __nbytes) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
338 void arc4random_stir(void);
339 uint32_t
340 arc4random_uniform(uint32_t __upper_bound) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
341 #ifdef __BLOCKS__
342 int atexit_b(void (^ _Nonnull)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
343 void *bsearch_b(const void *__key, const void *__base, size_t __nel,
344 size_t __width, int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
345 #endif /* __BLOCKS__ */
346
347 /* getcap(3) functions */
348 char *cgetcap(char *, const char *, int);
349 int cgetclose(void);
350 int cgetent(char **, char **, const char *);
351 int cgetfirst(char **, char **);
352 int cgetmatch(const char *, const char *);
353 int cgetnext(char **, char **);
354 int cgetnum(char *, const char *, long *);
355 int cgetset(const char *);
356 int cgetstr(char *, const char *, char **);
357 int cgetustr(char *, const char *, char **);
358
359 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;
360 char *devname(dev_t, mode_t);
361 char *devname_r(dev_t, mode_t, char *buf, int len);
362 char *getbsize(int *, long *);
363 int getloadavg(double [], int);
364 const char
365 *getprogname(void);
366
367 int heapsort(void *__base, size_t __nel, size_t __width,
368 int (* _Nonnull __compar)(const void *, const void *));
369 #ifdef __BLOCKS__
370 int heapsort_b(void *__base, size_t __nel, size_t __width,
371 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
372 #endif /* __BLOCKS__ */
373 int mergesort(void *__base, size_t __nel, size_t __width,
374 int (* _Nonnull __compar)(const void *, const void *));
375 #ifdef __BLOCKS__
376 int mergesort_b(void *__base, size_t __nel, size_t __width,
377 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
378 #endif /* __BLOCKS__ */
379 void psort(void *__base, size_t __nel, size_t __width,
380 int (* _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
381 #ifdef __BLOCKS__
382 void psort_b(void *__base, size_t __nel, size_t __width,
383 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
384 #endif /* __BLOCKS__ */
385 void psort_r(void *__base, size_t __nel, size_t __width, void *,
386 int (* _Nonnull __compar)(void *, const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
387 #ifdef __BLOCKS__
388 void qsort_b(void *__base, size_t __nel, size_t __width,
389 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
390 #endif /* __BLOCKS__ */
391 void qsort_r(void *__base, size_t __nel, size_t __width, void *,
392 int (* _Nonnull __compar)(void *, const void *, const void *));
393 int radixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
394 unsigned __endbyte);
395 void setprogname(const char *);
396 int sradixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
397 unsigned __endbyte);
398 void sranddev(void);
399 void srandomdev(void);
400 void *reallocf(void *__ptr, size_t __size) __alloc_size(2);
401 #if !__DARWIN_NO_LONG_LONG
402 long long
403 strtoq(const char *__str, char **__endptr, int __base);
404 unsigned long long
405 strtouq(const char *__str, char **__endptr, int __base);
406 #endif /* !__DARWIN_NO_LONG_LONG */
407 extern char *suboptarg; /* getsubopt(3) external variable */
408 void *valloc(size_t) __alloc_size(1);
409 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
410
411 /* Poison the following routines if -fshort-wchar is set */
412 #if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU
413 #pragma GCC poison mbstowcs mbtowc wcstombs wctomb
414 #endif
415 __END_DECLS
416
417 #ifdef _USE_EXTENDED_LOCALES_
418 #include <xlocale/_stdlib.h>
419 #endif /* _USE_EXTENDED_LOCALES_ */
420
421 #endif /* _STDLIB_H_ */