Ticket #2: stdlib.h

File stdlib.h, 11.5 KB (added by ezyang, 2 years ago)

stdlib.h file from Mac OS X

Line 
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 */
75typedef __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
81typedef __darwin_ct_rune_t      ct_rune_t;
82#endif
83
84#ifndef _RUNE_T
85#define _RUNE_T
86typedef __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
93typedef __darwin_wchar_t        wchar_t;
94#endif  /* _WCHAR_T */
95#endif  /* __cplusplus */
96
97typedef struct {
98        int quot;               /* quotient */
99        int rem;                /* remainder */
100} div_t;
101
102typedef struct {
103        long quot;              /* quotient */
104        long rem;               /* remainder */
105} ldiv_t;
106
107#if !__DARWIN_NO_LONG_LONG
108typedef 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_ */
134extern 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
144__BEGIN_DECLS
145void     abort(void) __dead2;
146int      abs(int) __pure2;
147int      atexit(void (*)(void));
148double   atof(const char *);
149int      atoi(const char *);
150long     atol(const char *);
151#if !__DARWIN_NO_LONG_LONG
152long long
153         atoll(const char *);
154#endif /* !__DARWIN_NO_LONG_LONG */
155void    *bsearch(const void *, const void *, size_t,
156            size_t, int (*)(const void *, const void *));
157void    *calloc(size_t, size_t);
158div_t    div(int, int) __pure2;
159void     exit(int) __dead2;
160void     free(void *);
161char    *getenv(const char *);
162long     labs(long) __pure2;
163ldiv_t   ldiv(long, long) __pure2;
164#if !__DARWIN_NO_LONG_LONG
165long long
166         llabs(long long);
167lldiv_t  lldiv(long long, long long);
168#endif /* !__DARWIN_NO_LONG_LONG */
169void    *malloc(size_t);
170int      mblen(const char *, size_t);
171size_t   mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
172int      mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
173int      posix_memalign(void **, size_t, size_t);
174void     qsort(void *, size_t, size_t,
175            int (*)(const void *, const void *));
176int      rand(void);
177void    *realloc(void *, size_t);
178void     srand(unsigned);
179double   strtod(const char *, char **) __DARWIN_ALIAS(strtod);
180float    strtof(const char *, char **) __DARWIN_ALIAS(strtof);
181long     strtol(const char *, char **, int);
182long double
183         strtold(const char *, char **) __DARWIN_LDBL_COMPAT(strtold);
184#if !__DARWIN_NO_LONG_LONG
185long long 
186         strtoll(const char *, char **, int);
187#endif /* !__DARWIN_NO_LONG_LONG */
188unsigned long
189         strtoul(const char *, char **, int);
190#if !__DARWIN_NO_LONG_LONG
191unsigned long long
192         strtoull(const char *, char **, int);
193#endif /* !__DARWIN_NO_LONG_LONG */
194int      system(const char *) __DARWIN_ALIAS_C(system);
195size_t   wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
196int      wctomb(char *, wchar_t);
197
198#ifndef _ANSI_SOURCE
199void    _Exit(int) __dead2;
200long     a64l(const char *);
201double   drand48(void);
202char    *ecvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
203double   erand48(unsigned short[3]); 
204char    *fcvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
205char    *gcvt(double, int, char *); /* LEGACY */
206int      getsubopt(char **, char * const *, char **);
207int      grantpt(int);
208#if __DARWIN_UNIX03
209char    *initstate(unsigned, char *, size_t); /* no  __DARWIN_ALIAS needed */
210#else /* !__DARWIN_UNIX03 */
211char    *initstate(unsigned long, char *, long);
212#endif /* __DARWIN_UNIX03 */
213long     jrand48(unsigned short[3]);
214char    *l64a(long);
215void     lcong48(unsigned short[7]);
216long     lrand48(void);
217char    *mktemp(char *);
218int      mkstemp(char *);
219long     mrand48(void); 
220long     nrand48(unsigned short[3]);
221int      posix_openpt(int);
222char    *ptsname(int);
223int      putenv(char *) __DARWIN_ALIAS(putenv);
224long     random(void);
225int      rand_r(unsigned *);
226#if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
227char    *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
228#else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */
229char    *realpath(const char * __restrict, char * __restrict) __DARWIN_ALIAS(realpath);
230#endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */
231unsigned short
232        *seed48(unsigned short[3]);
233int      setenv(const char *, const char *, int) __DARWIN_ALIAS(setenv);
234#if __DARWIN_UNIX03
235void     setkey(const char *) __DARWIN_ALIAS(setkey);
236#else /* !__DARWIN_UNIX03 */
237int      setkey(const char *);
238#endif /* __DARWIN_UNIX03 */
239char    *setstate(const char *);
240void     srand48(long);
241#if __DARWIN_UNIX03
242void     srandom(unsigned);
243#else /* !__DARWIN_UNIX03 */
244void     srandom(unsigned long);
245#endif /* __DARWIN_UNIX03 */
246int      unlockpt(int);
247#if __DARWIN_UNIX03
248int      unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
249#else /* !__DARWIN_UNIX03 */
250void     unsetenv(const char *);
251#endif /* __DARWIN_UNIX03 */
252#endif  /* !_ANSI_SOURCE */
253
254#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
255#include <machine/types.h>
256
257#ifndef _DEV_T
258typedef __darwin_dev_t  dev_t;
259#define _DEV_T
260#endif
261
262#ifndef _MODE_T
263typedef __darwin_mode_t mode_t;
264#define _MODE_T
265#endif
266
267u_int32_t
268         arc4random(void);
269void     arc4random_addrandom(unsigned char *dat, int datlen);
270void     arc4random_stir(void);
271#ifdef __BLOCKS__
272int      atexit_b(void (^)(void));
273void    *bsearch_b(const void *, const void *, size_t,
274            size_t, int (^)(const void *, const void *));
275#endif /* __BLOCKS__ */
276
277         /* getcap(3) functions */
278char    *cgetcap(char *, const char *, int);
279int      cgetclose(void);
280int      cgetent(char **, char **, const char *);
281int      cgetfirst(char **, char **);
282int      cgetmatch(const char *, const char *);
283int      cgetnext(char **, char **);
284int      cgetnum(char *, const char *, long *);
285int      cgetset(const char *);
286int      cgetstr(char *, const char *, char **);
287int      cgetustr(char *, const char *, char **);
288
289int      daemon(int, int) __DARWIN_1050(daemon) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_2_0,__IPHONE_2_0);
290char    *devname(dev_t, mode_t);
291char    *devname_r(dev_t, mode_t, char *buf, int len);
292char    *getbsize(int *, long *);
293int      getloadavg(double [], int);
294const char
295        *getprogname(void);
296
297int      heapsort(void *, size_t, size_t,
298            int (*)(const void *, const void *));
299#ifdef __BLOCKS__
300int      heapsort_b(void *, size_t, size_t,
301            int (^)(const void *, const void *));
302#endif /* __BLOCKS__ */
303int      mergesort(void *, size_t, size_t,
304            int (*)(const void *, const void *));
305#ifdef __BLOCKS__
306int      mergesort_b(void *, size_t, size_t,
307            int (^)(const void *, const void *));
308#endif /* __BLOCKS__ */
309void     psort(void *, size_t, size_t,
310            int (*)(const void *, const void *));
311#ifdef __BLOCKS__
312void     psort_b(void *, size_t, size_t,
313            int (^)(const void *, const void *));
314#endif /* __BLOCKS__ */
315void     psort_r(void *, size_t, size_t, void *,
316            int (*)(void *, const void *, const void *));
317#ifdef __BLOCKS__
318void     qsort_b(void *, size_t, size_t,
319            int (^)(const void *, const void *));
320#endif /* __BLOCKS__ */
321void     qsort_r(void *, size_t, size_t, void *,
322            int (*)(void *, const void *, const void *));
323int      radixsort(const unsigned char **, int, const unsigned char *,
324            unsigned);
325void     setprogname(const char *);
326int      sradixsort(const unsigned char **, int, const unsigned char *,
327            unsigned);
328void     sranddev(void);
329void     srandomdev(void);
330void    *reallocf(void *, size_t);
331#if !__DARWIN_NO_LONG_LONG
332long long
333         strtoq(const char *, char **, int);
334unsigned long long
335         strtouq(const char *, char **, int);
336#endif /* !__DARWIN_NO_LONG_LONG */
337extern char *suboptarg;         /* getsubopt(3) external variable */
338void    *valloc(size_t);
339#endif  /* !_ANSI_SOURCE && !_POSIX_SOURCE */
340
341/* Poison the following routines if -fshort-wchar is set */
342#if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU
343#pragma GCC poison mbstowcs mbtowc wcstombs wctomb
344#endif
345__END_DECLS
346
347#ifdef _USE_EXTENDED_LOCALES_
348#include <xlocale/_stdlib.h>
349#endif /* _USE_EXTENDED_LOCALES_ */
350
351#endif /* _STDLIB_H_ */