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#include <sys/cdefs.h>
63
64#include <_types.h>
65#if !defined(_ANSI_SOURCE)
66#include <sys/wait.h>
67#if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
68#include <alloca.h>
69#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
70#endif /* !_ANSI_SOURCE */
71
72/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
73 * _GCC_SIZE_T */
74#include <sys/_types/_size_t.h>
75
76#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
77#include <sys/_types/_ct_rune_t.h>
78#include <sys/_types/_rune_t.h>
79#endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
80
81#include <sys/_types/_wchar_t.h>
82
83typedef struct {
84 int quot; /* quotient */
85 int rem; /* remainder */
86} div_t;
87
88typedef struct {
89 long quot; /* quotient */
90 long rem; /* remainder */
91} ldiv_t;
92
93#if !__DARWIN_NO_LONG_LONG
94typedef struct {
95 long long quot;
96 long long rem;
97} lldiv_t;
98#endif /* !__DARWIN_NO_LONG_LONG */
99
100#include <sys/_types/_null.h>
101
102#define EXIT_FAILURE 1
103#define EXIT_SUCCESS 0
104
105#define RAND_MAX 0x7fffffff
106
107#ifdef _USE_EXTENDED_LOCALES_
108#include <_xlocale.h>
109#endif /* _USE_EXTENDED_LOCALES_ */
110
111#ifndef MB_CUR_MAX
112#ifdef _USE_EXTENDED_LOCALES_
113#define MB_CUR_MAX (___mb_cur_max())
114#ifndef MB_CUR_MAX_L
115#define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
116#endif /* !MB_CUR_MAX_L */
117#else /* !_USE_EXTENDED_LOCALES_ */
118extern int __mb_cur_max;
119#define MB_CUR_MAX __mb_cur_max
120#endif /* _USE_EXTENDED_LOCALES_ */
121#endif /* MB_CUR_MAX */
122
123#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) \
124 && defined(_USE_EXTENDED_LOCALES_) && !defined(MB_CUR_MAX_L)
125#define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
126#endif
127
128#include <malloc/_malloc.h>
129
130__BEGIN_DECLS
131void abort(void) __dead2;
132int abs(int) __pure2;
133int atexit(void (* _Nonnull)(void));
134double atof(const char *);
135int atoi(const char *);
136long atol(const char *);
137#if !__DARWIN_NO_LONG_LONG
138long long
139 atoll(const char *);
140#endif /* !__DARWIN_NO_LONG_LONG */
141void *bsearch(const void *__key, const void *__base, size_t __nel,
142 size_t __width, int (* _Nonnull __compar)(const void *, const void *));
143/* calloc is now declared in _malloc.h */
144div_t div(int, int) __pure2;
145void exit(int) __dead2;
146/* free is now declared in _malloc.h */
147char *getenv(const char *);
148long labs(long) __pure2;
149ldiv_t ldiv(long, long) __pure2;
150#if !__DARWIN_NO_LONG_LONG
151long long
152 llabs(long long);
153lldiv_t lldiv(long long, long long);
154#endif /* !__DARWIN_NO_LONG_LONG */
155/* malloc is now declared in _malloc.h */
156int mblen(const char *__s, size_t __n);
157size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
158int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
159/* posix_memalign is now declared in _malloc.h */
160void qsort(void *__base, size_t __nel, size_t __width,
161 int (* _Nonnull __compar)(const void *, const void *));
162int rand(void) __swift_unavailable("Use arc4random instead.");
163/* realloc is now declared in _malloc.h */
164void srand(unsigned) __swift_unavailable("Use arc4random instead.");
165double strtod(const char *, char **) __DARWIN_ALIAS(strtod);
166float strtof(const char *, char **) __DARWIN_ALIAS(strtof);
167long strtol(const char *__str, char **__endptr, int __base);
168long double
169 strtold(const char *, char **);
170#if !__DARWIN_NO_LONG_LONG
171long long
172 strtoll(const char *__str, char **__endptr, int __base);
173#endif /* !__DARWIN_NO_LONG_LONG */
174unsigned long
175 strtoul(const char *__str, char **__endptr, int __base);
176#if !__DARWIN_NO_LONG_LONG
177unsigned long long
178 strtoull(const char *__str, char **__endptr, int __base);
179#endif /* !__DARWIN_NO_LONG_LONG */
180
181#if TARGET_OS_EMBEDDED
182#define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(ios_msg)
183#else
184#define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(osx_msg)
185#endif
186
187__swift_unavailable_on("Use posix_spawn APIs or NSTask instead.", "Process spawning is unavailable")
188__API_AVAILABLE(macos(10.0)) __IOS_PROHIBITED
189__WATCHOS_PROHIBITED __TVOS_PROHIBITED
190int system(const char *) __DARWIN_ALIAS_C(system);
191
192#undef __swift_unavailable_on
193
194size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
195int wctomb(char *, wchar_t);
196
197#ifndef _ANSI_SOURCE
198void _Exit(int) __dead2;
199long a64l(const char *);
200double drand48(void);
201char *ecvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
202double erand48(unsigned short[3]);
203char *fcvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
204char *gcvt(double, int, char *); /* LEGACY */
205int getsubopt(char **, char * const *, char **);
206int grantpt(int);
207#if __DARWIN_UNIX03
208char *initstate(unsigned, char *, size_t); /* no __DARWIN_ALIAS needed */
209#else /* !__DARWIN_UNIX03 */
210char *initstate(unsigned long, char *, long);
211#endif /* __DARWIN_UNIX03 */
212long jrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead.");
213char *l64a(long);
214void lcong48(unsigned short[7]);
215long lrand48(void) __swift_unavailable("Use arc4random instead.");
216char *mktemp(char *);
217int mkstemp(char *);
218long mrand48(void) __swift_unavailable("Use arc4random instead.");
219long nrand48(unsigned short[3]) __swift_unavailable("Use arc4random instead.");
220int posix_openpt(int);
221char *ptsname(int);
222
223#if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
224int ptsname_r(int fildes, char *buffer, size_t buflen) __API_AVAILABLE(macos(10.13.4), ios(11.3), tvos(11.3), watchos(4.3));
225#endif
226
227int putenv(char *) __DARWIN_ALIAS(putenv);
228long random(void) __swift_unavailable("Use arc4random instead.");
229int rand_r(unsigned *) __swift_unavailable("Use arc4random instead.");
230#if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
231char *realpath(const char * __restrict, char * __restrict) __DARWIN_EXTSN(realpath);
232#else /* (!__DARWIN_UNIX03 || _POSIX_C_SOURCE) && !_DARWIN_C_SOURCE && !_DARWIN_BETTER_REALPATH */
233char *realpath(const char * __restrict, char * __restrict) __DARWIN_ALIAS(realpath);
234#endif /* (__DARWIN_UNIX03 && _POSIX_C_SOURCE) || _DARWIN_C_SOURCE || _DARWIN_BETTER_REALPATH */
235unsigned short
236 *seed48(unsigned short[3]);
237int setenv(const char * __name, const char * __value, int __overwrite) __DARWIN_ALIAS(setenv);
238#if __DARWIN_UNIX03
239void setkey(const char *) __DARWIN_ALIAS(setkey);
240#else /* !__DARWIN_UNIX03 */
241int setkey(const char *);
242#endif /* __DARWIN_UNIX03 */
243char *setstate(const char *);
244void srand48(long);
245#if __DARWIN_UNIX03
246void srandom(unsigned);
247#else /* !__DARWIN_UNIX03 */
248void srandom(unsigned long);
249#endif /* __DARWIN_UNIX03 */
250int unlockpt(int);
251#if __DARWIN_UNIX03
252int unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
253#else /* !__DARWIN_UNIX03 */
254void unsetenv(const char *);
255#endif /* __DARWIN_UNIX03 */
256#endif /* !_ANSI_SOURCE */
257
258#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
259#include <machine/types.h>
260
261#include <sys/_types/_dev_t.h>
262#include <sys/_types/_mode_t.h>
263#include <_types/_uint32_t.h>
264
265uint32_t arc4random(void);
266void arc4random_addrandom(unsigned char * /*dat*/, int /*datlen*/)
267 __OSX_DEPRECATED(10.0, 10.12, "use arc4random_stir")
268 __IOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
269 __TVOS_DEPRECATED(2.0, 10.0, "use arc4random_stir")
270 __WATCHOS_DEPRECATED(1.0, 3.0, "use arc4random_stir");
271void arc4random_buf(void * __buf, size_t __nbytes) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
272void arc4random_stir(void);
273uint32_t
274 arc4random_uniform(uint32_t __upper_bound) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
275#ifdef __BLOCKS__
276int atexit_b(void (^ _Nonnull)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
277void *bsearch_b(const void *__key, const void *__base, size_t __nel,
278 size_t __width, int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
279#endif /* __BLOCKS__ */
280
281 /* getcap(3) functions */
282char *cgetcap(char *, const char *, int);
283int cgetclose(void);
284int cgetent(char **, char **, const char *);
285int cgetfirst(char **, char **);
286int cgetmatch(const char *, const char *);
287int cgetnext(char **, char **);
288int cgetnum(char *, const char *, long *);
289int cgetset(const char *);
290int cgetstr(char *, const char *, char **);
291int cgetustr(char *, const char *, char **);
292
293int 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;
294char *devname(dev_t, mode_t);
295char *devname_r(dev_t, mode_t, char *buf, int len);
296char *getbsize(int *, long *);
297int getloadavg(double [], int);
298const char
299 *getprogname(void);
300
301int heapsort(void *__base, size_t __nel, size_t __width,
302 int (* _Nonnull __compar)(const void *, const void *));
303#ifdef __BLOCKS__
304int heapsort_b(void *__base, size_t __nel, size_t __width,
305 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
306#endif /* __BLOCKS__ */
307int mergesort(void *__base, size_t __nel, size_t __width,
308 int (* _Nonnull __compar)(const void *, const void *));
309#ifdef __BLOCKS__
310int mergesort_b(void *__base, size_t __nel, size_t __width,
311 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
312#endif /* __BLOCKS__ */
313void psort(void *__base, size_t __nel, size_t __width,
314 int (* _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
315#ifdef __BLOCKS__
316void psort_b(void *__base, size_t __nel, size_t __width,
317 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
318#endif /* __BLOCKS__ */
319void psort_r(void *__base, size_t __nel, size_t __width, void *,
320 int (* _Nonnull __compar)(void *, const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
321#ifdef __BLOCKS__
322void qsort_b(void *__base, size_t __nel, size_t __width,
323 int (^ _Nonnull __compar)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
324#endif /* __BLOCKS__ */
325void qsort_r(void *__base, size_t __nel, size_t __width, void *,
326 int (* _Nonnull __compar)(void *, const void *, const void *));
327int radixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
328 unsigned __endbyte);
329void setprogname(const char *);
330int sradixsort(const unsigned char **__base, int __nel, const unsigned char *__table,
331 unsigned __endbyte);
332void sranddev(void);
333void srandomdev(void);
334void *reallocf(void *__ptr, size_t __size) __alloc_size(2);
335#if !__DARWIN_NO_LONG_LONG
336long long
337 strtoq(const char *__str, char **__endptr, int __base);
338unsigned long long
339 strtouq(const char *__str, char **__endptr, int __base);
340#endif /* !__DARWIN_NO_LONG_LONG */
341extern char *suboptarg; /* getsubopt(3) external variable */
342/* valloc is now declared in _malloc.h */
343#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
344
345/* Poison the following routines if -fshort-wchar is set */
346#if !defined(__cplusplus) && defined(__WCHAR_MAX__) && __WCHAR_MAX__ <= 0xffffU
347#pragma GCC poison mbstowcs mbtowc wcstombs wctomb
348#endif
349__END_DECLS
350
351#ifdef _USE_EXTENDED_LOCALES_
352#include <xlocale/_stdlib.h>
353#endif /* _USE_EXTENDED_LOCALES_ */
354
355#endif /* _STDLIB_H_ */
356