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