]> git.saurik.com Git - apple/libc.git/blob - include/stdlib.h
a8e5d8d56112253914f7923e8db70d160ac087c4
[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 //Begin-Libc
241 #ifndef LIBC_ALIAS_PUTENV
242 //End-Libc
243 int putenv(char *) __DARWIN_ALIAS(putenv);
244 //Begin-Libc
245 #else /* LIBC_ALIAS_PUTENV */
246 int putenv(char *) LIBC_ALIAS(putenv);
247 #endif /* !LIBC_ALIAS_PUTENV */
248 //End-Libc
249 long random(void) __swift_unavailable("Use arc4random instead.");
250 int rand_r(unsigned *) __swift_unavailable("Use arc4random instead.");
251 //Begin-Libc
252 #ifdef __LIBC__
253 #ifndef LIBC_ALIAS_REALPATH
254 char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
255 #else /* LIBC_ALIAS_REALPATH */
256 #ifdef VARIANT_DARWINEXTSN
257 char *realpath(const char * __restrict, char * __restrict) LIBC_EXTSN(realpath);
258 #else /* !VARIANT_DARWINEXTSN */
259 char *realpath(const char * __restrict, char * __restrict) LIBC_ALIAS(realpath);
260 #endif /* VARIANT_DARWINEXTSN */
261 #endif /* !LIBC_ALIAS_REALPATH */
262 #else /* !__LIBC__ */
263 //End-Libc
264 #if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
265 char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
266 #else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */
267 char *realpath(const char * __restrict, char * __restrict) __DARWIN_ALIAS(realpath);
268 #endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */
269 //Begin-Libc
270 #endif /* __LIBC__ */
271 //End-Libc
272 unsigned short
273 *seed48(unsigned short[3]);
274 //Begin-Libc
275 #ifndef LIBC_ALIAS_SETENV
276 //End-Libc
277 int setenv(const char * __name, const char * __value, int __overwrite) __DARWIN_ALIAS(setenv);
278 //Begin-Libc
279 #else /* LIBC_ALIAS_SETENV */
280 int setenv(const char * __name, const char * __value, int __overwrite) LIBC_ALIAS(setenv);
281 #endif /* !LIBC_ALIAS_SETENV */
282 //End-Libc
283 #if __DARWIN_UNIX03
284 //Begin-Libc
285 #ifndef LIBC_ALIAS_SETKEY
286 //End-Libc
287 void setkey(const char *) __DARWIN_ALIAS(setkey);
288 //Begin-Libc
289 #else /* LIBC_ALIAS_SETKEY */
290 void setkey(const char *) LIBC_ALIAS(setkey);
291 #endif /* !LIBC_ALIAS_SETKEY */
292 //End-Libc
293 #else /* !__DARWIN_UNIX03 */
294 int setkey(const char *);
295 #endif /* __DARWIN_UNIX03 */
296 char *setstate(const char *);
297 void srand48(long);
298 #if __DARWIN_UNIX03
299 void srandom(unsigned);
300 #else /* !__DARWIN_UNIX03 */
301 void srandom(unsigned long);
302 #endif /* __DARWIN_UNIX03 */
303 int unlockpt(int);
304 #if __DARWIN_UNIX03
305 //Begin-Libc
306 #ifndef LIBC_ALIAS_UNSETENV
307 //End-Libc
308 int unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
309 //Begin-Libc
310 #else /* LIBC_ALIAS_UNSETENV */
311 int unsetenv(const char *) LIBC_ALIAS(unsetenv);
312 #endif /* !LIBC_ALIAS_UNSETENV */
313 //End-Libc
314 #else /* !__DARWIN_UNIX03 */
315 void unsetenv(const char *);
316 #endif /* __DARWIN_UNIX03 */
317 #endif /* !_ANSI_SOURCE */
318
319 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
320 #include <machine/types.h>
321
322 #include <sys/_types/_dev_t.h>
323 #include <sys/_types/_mode_t.h>
324 #include <_types/_uint32_t.h>
325
326 uint32_t arc4random(void);
327 void arc4random_addrandom(unsigned char * /*dat*/, int /*datlen*/)
328 __OSX_DEPRECATED(10.0, 10.12, "use arc4random_stir")
329 __IOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
330 __TVOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
331 __WATCHOS_DEPRECATED(1.0, 3.0, "use arc4random_stir");
332 void arc4random_buf(void * __buf, size_t __nbytes) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
333 void arc4random_stir(void);
334 uint32_t
335 arc4random_uniform(uint32_t __upper_bound) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
336 #ifdef __BLOCKS__
337 int atexit_b(void (^ _Nonnull)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
338 void *bsearch_b(const void *__key, const void *__base, size_t __nel,
339 size_t __width, int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
340 #endif /* __BLOCKS__ */
341
342 /* getcap(3) functions */
343 char *cgetcap(char *, const char *, int);
344 int cgetclose(void);
345 int cgetent(char **, char **, const char *);
346 int cgetfirst(char **, char **);
347 int cgetmatch(const char *, const char *);
348 int cgetnext(char **, char **);
349 int cgetnum(char *, const char *, long *);
350 int cgetset(const char *);
351 int cgetstr(char *, const char *, char **);
352 int cgetustr(char *, const char *, char **);
353
354 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;
355 char *devname(dev_t, mode_t);
356 char *devname_r(dev_t, mode_t, char *buf, int len);
357 char *getbsize(int *, long *);
358 int getloadavg(double [], int);
359 const char
360 *getprogname(void);
361
362 int heapsort(void *__base, size_t __nel, size_t __width,
363 int (* _Nonnull __compar)(const void *, const void *));
364 #ifdef __BLOCKS__
365 int heapsort_b(void *__base, size_t __nel, size_t __width,
366 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
367 #endif /* __BLOCKS__ */
368 int mergesort(void *__base, size_t __nel, size_t __width,
369 int (* _Nonnull __compar)(const void *, const void *));
370 #ifdef __BLOCKS__
371 int mergesort_b(void *__base, size_t __nel, size_t __width,
372 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
373 #endif /* __BLOCKS__ */
374 void psort(void *__base, size_t __nel, size_t __width,
375 int (* _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
376 #ifdef __BLOCKS__
377 void psort_b(void *__base, size_t __nel, size_t __width,
378 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
379 #endif /* __BLOCKS__ */
380 void psort_r(void *__base, size_t __nel, size_t __width, void *,
381 int (* _Nonnull __compar)(void *, const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
382 #ifdef __BLOCKS__
383 void qsort_b(void *__base, size_t __nel, size_t __width,
384 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
385 #endif /* __BLOCKS__ */
386 void qsort_r(void *__base, size_t __nel, size_t __width, void *,
387 int (* _Nonnull __compar)(void *, const void *, const void *));
388 int radixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
389 unsigned __endbyte);
390 void setprogname(const char *);
391 int sradixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
392 unsigned __endbyte);
393 void sranddev(void);
394 void srandomdev(void);
395 void *reallocf(void *__ptr, size_t __size) __alloc_size(2);
396 #if !__DARWIN_NO_LONG_LONG
397 long long
398 strtoq(const char *__str, char **__endptr, int __base);
399 unsigned long long
400 strtouq(const char *__str, char **__endptr, int __base);
401 #endif /* !__DARWIN_NO_LONG_LONG */
402 extern char *suboptarg; /* getsubopt(3) external variable */
403 void *valloc(size_t) __alloc_size(1);
404 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
405
406 /* Poison the following routines if -fshort-wchar is set */
407 #if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU
408 #pragma GCC poison mbstowcs mbtowc wcstombs wctomb
409 #endif
410 __END_DECLS
411
412 #ifdef _USE_EXTENDED_LOCALES_
413 #include <xlocale/_stdlib.h>
414 #endif /* _USE_EXTENDED_LOCALES_ */
415
416 #endif /* _STDLIB_H_ */