]> git.saurik.com Git - apple/libc.git/blob - include/stdlib.h
77be6671d2d91b2b7341ca6e119f95b1a7ca6e57
[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 /* f must be a literal string */
128 #define LIBC_ABORT(f,...) abort_report_np("%s:%s:%u: " f, __FILE__, __func__, __LINE__, ## __VA_ARGS__)
129 //End-Libc
130
131 __BEGIN_DECLS
132 void abort(void) __dead2;
133 //Begin-Libc
134 __private_extern__
135 void abort_report_np(const char *, ...) __dead2 __printflike(1, 2);
136 //End-Libc
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
143 long long
144 atoll(const char *);
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;
151 void free(void *);
152 char *getenv(const char *);
153 long labs(long) __pure2;
154 ldiv_t ldiv(long, long) __pure2;
155 #if !__DARWIN_NO_LONG_LONG
156 long long
157 llabs(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 *));
167 int rand(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);
173 long double
174 strtold(const char *, char **);
175 #if !__DARWIN_NO_LONG_LONG
176 long long
177 strtoll(const char *, char **, int);
178 #endif /* !__DARWIN_NO_LONG_LONG */
179 unsigned long
180 strtoul(const char *, char **, int);
181 #if !__DARWIN_NO_LONG_LONG
182 unsigned long long
183 strtoull(const char *, char **, int);
184 #endif /* !__DARWIN_NO_LONG_LONG */
185 //Begin-Libc
186 #ifndef LIBC_ALIAS_SYSTEM
187 //End-Libc
188 int system(const char *) __DARWIN_ALIAS_C(system);
189 //Begin-Libc
190 #else /* LIBC_ALIAS_SYSTEM */
191 int system(const char *) LIBC_ALIAS_C(system);
192 #endif /* !LIBC_ALIAS_SYSTEM */
193 //End-Libc
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]);
213 char *l64a(long);
214 void lcong48(unsigned short[7]);
215 long lrand48(void);
216 char *mktemp(char *);
217 int mkstemp(char *);
218 long mrand48(void);
219 long nrand48(unsigned short[3]);
220 int posix_openpt(int);
221 char *ptsname(int);
222 //Begin-Libc
223 #ifndef LIBC_ALIAS_PUTENV
224 //End-Libc
225 int putenv(char *) __DARWIN_ALIAS(putenv);
226 //Begin-Libc
227 #else /* LIBC_ALIAS_PUTENV */
228 int putenv(char *) LIBC_ALIAS(putenv);
229 #endif /* !LIBC_ALIAS_PUTENV */
230 //End-Libc
231 long random(void);
232 int rand_r(unsigned *);
233 //Begin-Libc
234 #ifdef __LIBC__
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__ */
245 //End-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 */
251 //Begin-Libc
252 #endif /* __LIBC__ */
253 //End-Libc
254 unsigned short
255 *seed48(unsigned short[3]);
256 //Begin-Libc
257 #ifndef LIBC_ALIAS_SETENV
258 //End-Libc
259 int setenv(const char *, const char *, int) __DARWIN_ALIAS(setenv);
260 //Begin-Libc
261 #else /* LIBC_ALIAS_SETENV */
262 int setenv(const char *, const char *, int) LIBC_ALIAS(setenv);
263 #endif /* !LIBC_ALIAS_SETENV */
264 //End-Libc
265 #if __DARWIN_UNIX03
266 //Begin-Libc
267 #ifndef LIBC_ALIAS_SETKEY
268 //End-Libc
269 void setkey(const char *) __DARWIN_ALIAS(setkey);
270 //Begin-Libc
271 #else /* LIBC_ALIAS_SETKEY */
272 void setkey(const char *) LIBC_ALIAS(setkey);
273 #endif /* !LIBC_ALIAS_SETKEY */
274 //End-Libc
275 #else /* !__DARWIN_UNIX03 */
276 int setkey(const char *);
277 #endif /* __DARWIN_UNIX03 */
278 char *setstate(const char *);
279 void srand48(long);
280 #if __DARWIN_UNIX03
281 void srandom(unsigned);
282 #else /* !__DARWIN_UNIX03 */
283 void srandom(unsigned long);
284 #endif /* __DARWIN_UNIX03 */
285 int unlockpt(int);
286 #if __DARWIN_UNIX03
287 //Begin-Libc
288 #ifndef LIBC_ALIAS_UNSETENV
289 //End-Libc
290 int unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
291 //Begin-Libc
292 #else /* LIBC_ALIAS_UNSETENV */
293 int unsetenv(const char *) LIBC_ALIAS(unsetenv);
294 #endif /* !LIBC_ALIAS_UNSETENV */
295 //End-Libc
296 #else /* !__DARWIN_UNIX03 */
297 void unsetenv(const char *);
298 #endif /* __DARWIN_UNIX03 */
299 #endif /* !_ANSI_SOURCE */
300
301 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
302 #include <machine/types.h>
303
304 #include <sys/_types/_dev_t.h>
305 #include <sys/_types/_mode_t.h>
306
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);
311 u_int32_t
312 arc4random_uniform(u_int32_t /*upper_bound*/) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
313 #ifdef __BLOCKS__
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__ */
318
319 /* getcap(3) functions */
320 char *cgetcap(char *, const char *, int);
321 int cgetclose(void);
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 **);
330
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);
336 const char
337 *getprogname(void);
338
339 int heapsort(void *, size_t, size_t,
340 int (*)(const void *, const void *));
341 #ifdef __BLOCKS__
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 *));
347 #ifdef __BLOCKS__
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);
353 #ifdef __BLOCKS__
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);
359 #ifdef __BLOCKS__
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 *,
366 unsigned);
367 void setprogname(const char *);
368 int sradixsort(const unsigned char **, int, const unsigned char *,
369 unsigned);
370 void sranddev(void);
371 void srandomdev(void);
372 void *reallocf(void *, size_t);
373 #if !__DARWIN_NO_LONG_LONG
374 long long
375 strtoq(const char *, char **, int);
376 unsigned long long
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 */
382
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
386 #endif
387 __END_DECLS
388
389 #ifdef _USE_EXTENDED_LOCALES_
390 #include <xlocale/_stdlib.h>
391 #endif /* _USE_EXTENDED_LOCALES_ */
392
393 #endif /* _STDLIB_H_ */