]>
git.saurik.com Git - apple/libc.git/blob - include/stdlib.h
77be6671d2d91b2b7341ca6e119f95b1a7ca6e57
2 * Copyright (c) 2000, 2002 - 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1990, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
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.
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
55 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
61 #include <Availability.h>
64 #if !defined(_ANSI_SOURCE)
66 #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
68 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
69 #endif /* !_ANSI_SOURCE */
71 /* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
73 #include <sys/_types/_size_t.h>
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) */
80 #include <sys/_types/_wchar_t.h>
83 int quot
; /* quotient */
84 int rem
; /* remainder */
88 long quot
; /* quotient */
89 long rem
; /* remainder */
92 #if !__DARWIN_NO_LONG_LONG
97 #endif /* !__DARWIN_NO_LONG_LONG */
99 #include <sys/_types/_null.h>
101 #define EXIT_FAILURE 1
102 #define EXIT_SUCCESS 0
104 #define RAND_MAX 0x7fffffff
106 #ifdef _USE_EXTENDED_LOCALES_
107 #include <_xlocale.h>
108 #endif /* _USE_EXTENDED_LOCALES_ */
111 #ifdef _USE_EXTENDED_LOCALES_
112 #define MB_CUR_MAX (___mb_cur_max())
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 */
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))
127 /* f must be a literal string */
128 #define LIBC_ABORT(f,...) abort_report_np("%s:%s:%u: " f, __FILE__, __func__, __LINE__, ## __VA_ARGS__)
132 void abort(void) __dead2
;
135 void abort_report_np(const char *, ...) __dead2
__printflike(1, 2);
137 int abs(int) __pure2
;
138 int atexit(void (*)(void));
139 double atof(const char *);
140 int atoi(const char *);
141 long atol(const char *);
142 #if !__DARWIN_NO_LONG_LONG
145 #endif /* !__DARWIN_NO_LONG_LONG */
146 void *bsearch(const void *, const void *, size_t,
147 size_t, int (*)(const void *, const void *));
148 void *calloc(size_t, size_t);
149 div_t div(int, int) __pure2
;
150 void exit(int) __dead2
;
152 char *getenv(const char *);
153 long labs(long) __pure2
;
154 ldiv_t ldiv(long, long) __pure2
;
155 #if !__DARWIN_NO_LONG_LONG
158 lldiv_t
lldiv(long long, long long);
159 #endif /* !__DARWIN_NO_LONG_LONG */
160 void *malloc(size_t);
161 int mblen(const char *, size_t);
162 size_t mbstowcs(wchar_t * __restrict
, const char * __restrict
, size_t);
163 int mbtowc(wchar_t * __restrict
, const char * __restrict
, size_t);
164 int posix_memalign(void **, size_t, size_t) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_0
);
165 void qsort(void *, size_t, size_t,
166 int (*)(const void *, const void *));
168 void *realloc(void *, size_t);
169 void srand(unsigned);
170 double strtod(const char *, char **) __DARWIN_ALIAS(strtod
);
171 float strtof(const char *, char **) __DARWIN_ALIAS(strtof
);
172 long strtol(const char *, char **, int);
174 strtold(const char *, char **);
175 #if !__DARWIN_NO_LONG_LONG
177 strtoll(const char *, char **, int);
178 #endif /* !__DARWIN_NO_LONG_LONG */
180 strtoul(const char *, char **, int);
181 #if !__DARWIN_NO_LONG_LONG
183 strtoull(const char *, char **, int);
184 #endif /* !__DARWIN_NO_LONG_LONG */
186 #ifndef LIBC_ALIAS_SYSTEM
188 int system(const char *) __DARWIN_ALIAS_C(system
);
190 #else /* LIBC_ALIAS_SYSTEM */
191 int system(const char *) LIBC_ALIAS_C(system
);
192 #endif /* !LIBC_ALIAS_SYSTEM */
194 size_t wcstombs(char * __restrict
, const wchar_t * __restrict
, size_t);
195 int wctomb(char *, wchar_t);
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 **);
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]);
214 void lcong48(unsigned short[7]);
216 char *mktemp(char *);
219 long nrand48(unsigned short[3]);
220 int posix_openpt(int);
223 #ifndef LIBC_ALIAS_PUTENV
225 int putenv(char *) __DARWIN_ALIAS(putenv
);
227 #else /* LIBC_ALIAS_PUTENV */
228 int putenv(char *) LIBC_ALIAS(putenv
);
229 #endif /* !LIBC_ALIAS_PUTENV */
232 int rand_r(unsigned *);
235 #ifndef LIBC_ALIAS_REALPATH
236 char *realpath(const char * __restrict
, char * __restrict
) __DARWIN_EXTSN(realpath
);
237 #else /* LIBC_ALIAS_REALPATH */
238 #ifdef VARIANT_DARWINEXTSN
239 char *realpath(const char * __restrict
, char * __restrict
) LIBC_EXTSN(realpath
);
240 #else /* !VARIANT_DARWINEXTSN */
241 char *realpath(const char * __restrict
, char * __restrict
) LIBC_ALIAS(realpath
);
242 #endif /* VARIANT_DARWINEXTSN */
243 #endif /* !LIBC_ALIAS_REALPATH */
244 #else /* !__LIBC__ */
246 #if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
247 char *realpath(const char * __restrict
, char * __restrict
) __DARWIN_EXTSN(realpath
);
248 #else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */
249 char *realpath(const char * __restrict
, char * __restrict
) __DARWIN_ALIAS(realpath
);
250 #endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */
252 #endif /* __LIBC__ */
255 *seed48(unsigned short[3]);
257 #ifndef LIBC_ALIAS_SETENV
259 int setenv(const char *, const char *, int) __DARWIN_ALIAS(setenv
);
261 #else /* LIBC_ALIAS_SETENV */
262 int setenv(const char *, const char *, int) LIBC_ALIAS(setenv
);
263 #endif /* !LIBC_ALIAS_SETENV */
267 #ifndef LIBC_ALIAS_SETKEY
269 void setkey(const char *) __DARWIN_ALIAS(setkey
);
271 #else /* LIBC_ALIAS_SETKEY */
272 void setkey(const char *) LIBC_ALIAS(setkey
);
273 #endif /* !LIBC_ALIAS_SETKEY */
275 #else /* !__DARWIN_UNIX03 */
276 int setkey(const char *);
277 #endif /* __DARWIN_UNIX03 */
278 char *setstate(const char *);
281 void srandom(unsigned);
282 #else /* !__DARWIN_UNIX03 */
283 void srandom(unsigned long);
284 #endif /* __DARWIN_UNIX03 */
288 #ifndef LIBC_ALIAS_UNSETENV
290 int unsetenv(const char *) __DARWIN_ALIAS(unsetenv
);
292 #else /* LIBC_ALIAS_UNSETENV */
293 int unsetenv(const char *) LIBC_ALIAS(unsetenv
);
294 #endif /* !LIBC_ALIAS_UNSETENV */
296 #else /* !__DARWIN_UNIX03 */
297 void unsetenv(const char *);
298 #endif /* __DARWIN_UNIX03 */
299 #endif /* !_ANSI_SOURCE */
301 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
302 #include <machine/types.h>
304 #include <sys/_types/_dev_t.h>
305 #include <sys/_types/_mode_t.h>
307 u_int32_t
arc4random(void);
308 void arc4random_addrandom(unsigned char * /*dat*/, int /*datlen*/);
309 void arc4random_buf(void * /*buf*/, size_t /*nbytes*/) __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_4_3
);
310 void arc4random_stir(void);
312 arc4random_uniform(u_int32_t
/*upper_bound*/) __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_4_3
);
314 int atexit_b(void (^)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
315 void *bsearch_b(const void *, const void *, size_t,
316 size_t, int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
317 #endif /* __BLOCKS__ */
319 /* getcap(3) functions */
320 char *cgetcap(char *, const char *, int);
322 int cgetent(char **, char **, const char *);
323 int cgetfirst(char **, char **);
324 int cgetmatch(const char *, const char *);
325 int cgetnext(char **, char **);
326 int cgetnum(char *, const char *, long *);
327 int cgetset(const char *);
328 int cgetstr(char *, const char *, char **);
329 int cgetustr(char *, const char *, char **);
331 int daemon(int, int) __DARWIN_1050(daemon
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0
, __MAC_10_5
, __IPHONE_2_0
, __IPHONE_2_0
);
332 char *devname(dev_t
, mode_t
);
333 char *devname_r(dev_t
, mode_t
, char *buf
, int len
);
334 char *getbsize(int *, long *);
335 int getloadavg(double [], int);
339 int heapsort(void *, size_t, size_t,
340 int (*)(const void *, const void *));
342 int heapsort_b(void *, size_t, size_t,
343 int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
344 #endif /* __BLOCKS__ */
345 int mergesort(void *, size_t, size_t,
346 int (*)(const void *, const void *));
348 int mergesort_b(void *, size_t, size_t,
349 int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
350 #endif /* __BLOCKS__ */
351 void psort(void *, size_t, size_t,
352 int (*)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
354 void psort_b(void *, size_t, size_t,
355 int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
356 #endif /* __BLOCKS__ */
357 void psort_r(void *, size_t, size_t, void *,
358 int (*)(void *, const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
360 void qsort_b(void *, size_t, size_t,
361 int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_2
);
362 #endif /* __BLOCKS__ */
363 void qsort_r(void *, size_t, size_t, void *,
364 int (*)(void *, const void *, const void *));
365 int radixsort(const unsigned char **, int, const unsigned char *,
367 void setprogname(const char *);
368 int sradixsort(const unsigned char **, int, const unsigned char *,
371 void srandomdev(void);
372 void *reallocf(void *, size_t);
373 #if !__DARWIN_NO_LONG_LONG
375 strtoq(const char *, char **, int);
377 strtouq(const char *, char **, int);
378 #endif /* !__DARWIN_NO_LONG_LONG */
379 extern char *suboptarg
; /* getsubopt(3) external variable */
380 void *valloc(size_t);
381 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
383 /* Poison the following routines if -fshort-wchar is set */
384 #if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU
385 #pragma GCC poison mbstowcs mbtowc wcstombs wctomb
389 #ifdef _USE_EXTENDED_LOCALES_
390 #include <xlocale/_stdlib.h>
391 #endif /* _USE_EXTENDED_LOCALES_ */
393 #endif /* _STDLIB_H_ */