2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
34 * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $
40 #include <sys/cdefs.h>
41 #include <sys/_null.h>
42 #include <sys/types.h>
44 #ifndef _SIZE_T_DECLARED
45 typedef __size_t
size_t;
46 #define _SIZE_T_DECLARED
50 #ifndef _WCHAR_T_DECLARED
51 typedef __wchar_t
wchar_t;
52 #define _WCHAR_T_DECLARED
57 int quot
; /* quotient */
58 int rem
; /* remainder */
66 #define EXIT_FAILURE 1
67 #define EXIT_SUCCESS 0
69 #define RAND_MAX 0x7fffffff
71 extern int __mb_cur_max
;
72 #define MB_CUR_MAX __mb_cur_max
75 void abort(void) __dead2
;
76 /* void abort2(const char *, int, void **) __dead2; */
77 #if !defined(_KERNEL_VIRTUAL)
80 int atexit(void (*)(void));
81 double atof(const char *);
82 int atoi(const char *);
83 long atol(const char *);
84 void *bsearch(const void *, const void *, size_t,
85 size_t, int (*)(const void *, const void *));
86 void *calloc(size_t, size_t);
87 div_t div(int, int) __pure2
;
88 void exit(int) __dead2
;
90 char *getenv(const char *);
91 #if !defined(_KERNEL_VIRTUAL)
92 long labs(long) __pure2
;
94 ldiv_t ldiv(long, long) __pure2
;
96 int posix_memalign(void **, size_t, size_t);
97 int mblen(const char *, size_t);
98 size_t mbstowcs(wchar_t * __restrict
, const char * __restrict
, size_t);
99 int mbtowc(wchar_t * __restrict
, const char * __restrict
, size_t);
100 void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
102 void *realloc(void *, size_t);
103 void srand(unsigned);
104 double strtod(const char * __restrict
, char ** __restrict
);
105 float strtof(const char * __restrict
, char ** __restrict
);
106 #if !defined(_KERNEL_VIRTUAL)
107 long strtol(const char * __restrict
, char ** __restrict
, int);
110 strtold(const char * __restrict
, char ** __restrict
);
111 #if !defined(_KERNEL_VIRTUAL)
113 strtoul(const char * __restrict
, char ** __restrict
, int);
115 int system(const char *);
116 int wctomb(char *, wchar_t);
117 size_t wcstombs(char * __restrict
, const wchar_t * __restrict
, size_t);
120 * Functions added in C99 which we make conditionally available in the
121 * BSD^C89 namespace if the compiler supports `long long'.
122 * The #if test is more complicated than it ought to be because
123 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
124 * is not supported in the compilation environment (which therefore means
125 * that it can't really be ISO C99).
127 * (The only other extension made by C99 in this header is _Exit().)
129 #if __ISO_C_VISIBLE >= 1999
130 #ifdef __LONG_LONG_SUPPORTED
142 llabs(long long) __pure2
;
144 lldiv_t
lldiv(long long, long long) __pure2
;
147 strtoll(const char * __restrict
, char ** __restrict
, int);
150 strtoull(const char * __restrict
, char ** __restrict
, int);
151 #endif /* __LONG_LONG_SUPPORTED */
153 void _Exit(int) __dead2
;
154 #endif /* __ISO_C_VISIBLE >= 1999 */
157 * Extensions made by POSIX relative to C. We don't know yet which edition
158 * of POSIX made these extensions, so assume they've always been there until
159 * research can be done.
161 #if __POSIX_VISIBLE /* >= ??? */
162 /*int posix_memalign(void **, size_t, size_t); (ADV) */
163 int rand_r(unsigned *); /* (TSF) */
164 int setenv(const char *, const char *, int);
165 int unsetenv(const char *);
168 #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
169 #ifndef _MKDTEMP_DECLARED
170 char *mkdtemp(char *);
171 #define _MKDTEMP_DECLARED
173 #ifndef _MKSTEMP_DECLARED
175 #define _MKSTEMP_DECLARED
177 #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
180 * The only changes to the XSI namespace in revision 6 were the deletion
181 * of the ttyslot() and valloc() functions, which we never declared
182 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which
183 * we also do not have, and mktemp(), are to be deleted.
186 /* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */
187 long a64l(const char *);
188 double drand48(void);
189 /* char *ecvt(double, int, int * __restrict, int * __restrict); */
190 double erand48(unsigned short[3]);
191 /* char *fcvt(double, int, int * __restrict, int * __restrict); */
192 /* char *gcvt(double, int, int * __restrict, int * __restrict); */
193 int getsubopt(char **, char *const *, char **);
195 char *initstate(unsigned long /* XSI requires u_int */, char *, long);
196 long jrand48(unsigned short[3]);
198 void lcong48(unsigned short[7]);
200 #if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600)
201 char *mktemp(char *);
202 #define _MKTEMP_DECLARED
205 long nrand48(unsigned short[3]);
206 int posix_openpt(int);
210 char *realpath(const char * __restrict
, char * __restrict
);
212 *seed48(unsigned short[3]);
213 int setkey(const char *);
214 char *setstate(/* const */ char *);
216 void srandom(unsigned long);
218 #endif /* __XSI_VISIBLE */
221 /* extern const char *_malloc_options;
222 extern void (*_malloc_message)(const char *, const char *, const char *,
226 * The alloca() function can't be implemented in C, and on some
227 * platforms it can't be implemented at all as a callable function.
228 * The GNU C compiler provides a built-in alloca() which we can use;
229 * in all other cases, provide a prototype, mainly to pacify various
230 * incarnations of lint. On platforms where alloca() is not in libc,
231 * programs which use it will fail to link when compiled with non-GNU
234 #if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
235 #undef alloca /* some GNU bits try to get cute and define this on their own */
236 #define alloca(sz) __builtin_alloca(sz)
238 void *alloca(size_t);
243 void arc4random_addrandom(__uint8_t
*, size_t);
244 void arc4random_buf(void *, size_t);
245 void arc4random_stir(void);
247 arc4random_uniform(__uint32_t
);
248 char *getbsize(int *, long *);
250 /* getcap(3) functions */
251 char *cgetcap(char *, const char *, int);
253 int cgetent(char **, char **, const char *);
254 int cgetfirst(char **, char **);
255 int cgetmatch(const char *, const char *);
256 int cgetnext(char **, char **);
257 int cgetnum(char *, const char *, long *);
258 int cgetset(const char *);
259 int cgetstr(char *, const char *, char **);
260 int cgetustr(char *, const char *, char **);
262 int daemon(int, int);
263 char *devname(dev_t
, mode_t
);
264 char *devname_r(dev_t
, mode_t
, char *, size_t);
266 int fdevname_r(int, char *, size_t);
267 int getloadavg(double [], int);
271 int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
272 int l64a_r(long, char *, int);
273 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
274 void qsort_r(void *, size_t, size_t, void *,
275 int (*)(void *, const void *, const void *));
276 int radixsort(const unsigned char **, int, const unsigned char *,
278 void *reallocf(void *, size_t);
279 int rpmatch(const char *);
280 void setprogname(const char *);
281 int sradixsort(const unsigned char **, int, const unsigned char *,
284 void srandomdev(void);
286 strtonum(const char *, long long, long long, const char **);
288 /* Deprecated interfaces. */
289 #if !defined(_KERNEL_VIRTUAL)
291 strtoq(const char *, char **, int);
293 strtouq(const char *, char **, int);
296 extern char *suboptarg
; /* getsubopt(3) external variable */
297 #endif /* __BSD_VISIBLE */
302 #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L || __BSD_VISIBLE
303 int at_quick_exit(void (*func
)(void));
304 void quick_exit(int) __dead2
;
305 void *aligned_alloc(size_t, size_t);
306 #endif /* __ISO_C_VISIBLE >= 2011 */
310 #endif /* !_STDLIB_H_ */