Commit | Line | Data |
---|---|---|
984263bc MD |
1 | /*- |
2 | * Copyright (c) 1990, 1993 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
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. | |
bc7a8293 | 13 | * 3. Neither the name of the University nor the names of its contributors |
984263bc MD |
14 | * may be used to endorse or promote products derived from this software |
15 | * without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | |
28 | * | |
29 | * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 | |
5d0641a4 | 30 | * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $ |
984263bc MD |
31 | */ |
32 | ||
33 | #ifndef _STDLIB_H_ | |
34 | #define _STDLIB_H_ | |
35 | ||
36 | #include <sys/cdefs.h> | |
5d0641a4 | 37 | #include <sys/_null.h> |
fa261b1d | 38 | #include <sys/types.h> |
3cfdabcf | 39 | #ifndef __cplusplus |
40 | #include <machine/wchar.h> /* for ___wchar_t */ | |
41 | #endif | |
faed5989 | 42 | #if __BSD_VISIBLE |
8f546928 | 43 | #include <malloc_np.h> /* for malloc_usable_size */ |
faed5989 | 44 | #endif |
984263bc | 45 | |
5d0641a4 | 46 | #ifndef _SIZE_T_DECLARED |
2d418273 | 47 | typedef __size_t size_t; /* _GCC_SIZE_T OK */ |
5d0641a4 | 48 | #define _SIZE_T_DECLARED |
e2565a42 | 49 | #endif |
984263bc | 50 | |
5d0641a4 | 51 | #ifndef __cplusplus |
a81b3ef3 | 52 | #ifndef _WCHAR_T_DECLARED |
3cfdabcf | 53 | typedef ___wchar_t wchar_t; /* _GCC_WCHAR_T OK */ |
5d0641a4 | 54 | #define _WCHAR_T_DECLARED |
984263bc | 55 | #endif |
984263bc | 56 | #endif |
e2565a42 | 57 | |
086b156c | 58 | #if __EXT1_VISIBLE |
258eae18 | 59 | #ifndef _ERRNO_T_DECLARED |
086b156c | 60 | typedef int errno_t; |
258eae18 | 61 | #define _ERRNO_T_DECLARED |
086b156c SW |
62 | #endif |
63 | #endif | |
64 | ||
984263bc | 65 | typedef struct { |
5d0641a4 PA |
66 | int quot; /* quotient */ |
67 | int rem; /* remainder */ | |
984263bc MD |
68 | } div_t; |
69 | ||
70 | typedef struct { | |
5d0641a4 PA |
71 | long quot; |
72 | long rem; | |
984263bc MD |
73 | } ldiv_t; |
74 | ||
984263bc MD |
75 | #define EXIT_FAILURE 1 |
76 | #define EXIT_SUCCESS 0 | |
77 | ||
78 | #define RAND_MAX 0x7fffffff | |
79 | ||
0d5acd74 JM |
80 | __BEGIN_DECLS |
81 | #ifdef _XLOCALE_H_ | |
82 | #include <xlocale/_stdlib.h> | |
83 | #endif | |
984263bc | 84 | extern int __mb_cur_max; |
0d5acd74 | 85 | extern int ___mb_cur_max(void); |
b345f56c | 86 | #define MB_CUR_MAX ((size_t)___mb_cur_max()) |
984263bc | 87 | |
5baeefc7 | 88 | void abort(void) __dead2; |
5d0641a4 | 89 | /* void abort2(const char *, int, void **) __dead2; */ |
4d42eed2 | 90 | #if !defined(_KERNEL_VIRTUAL) |
5baeefc7 | 91 | int abs(int) __pure2; |
4d42eed2 | 92 | #endif |
5baeefc7 JS |
93 | int atexit(void (*)(void)); |
94 | double atof(const char *); | |
95 | int atoi(const char *); | |
96 | long atol(const char *); | |
97 | void *bsearch(const void *, const void *, size_t, | |
98 | size_t, int (*)(const void *, const void *)); | |
fc0e4e26 | 99 | void *calloc(size_t, size_t) __alloc_size2(1, 2) __malloclike __heedresult; |
5baeefc7 JS |
100 | div_t div(int, int) __pure2; |
101 | void exit(int) __dead2; | |
102 | void free(void *); | |
103 | char *getenv(const char *); | |
4d42eed2 | 104 | #if !defined(_KERNEL_VIRTUAL) |
5baeefc7 | 105 | long labs(long) __pure2; |
4d42eed2 | 106 | #endif |
5baeefc7 | 107 | ldiv_t ldiv(long, long) __pure2; |
3d258b72 | 108 | void *malloc(size_t) __malloclike __heedresult __alloc_size(1); |
5d0641a4 PA |
109 | int mblen(const char *, size_t); |
110 | size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); | |
111 | int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); | |
112 | void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); | |
5baeefc7 | 113 | int rand(void); |
3d258b72 | 114 | void *realloc(void *, size_t) __heedresult __alloc_size(2); |
5baeefc7 | 115 | void srand(unsigned); |
5d0641a4 | 116 | double strtod(const char * __restrict, char ** __restrict); |
f202adf7 | 117 | float strtof(const char * __restrict, char ** __restrict); |
5d0641a4 PA |
118 | #if !defined(_KERNEL_VIRTUAL) |
119 | long strtol(const char * __restrict, char ** __restrict, int); | |
984263bc | 120 | #endif |
f202adf7 PA |
121 | long double |
122 | strtold(const char * __restrict, char ** __restrict); | |
44a09dd6 | 123 | #if !defined(_KERNEL_VIRTUAL) |
5d0641a4 PA |
124 | unsigned long |
125 | strtoul(const char * __restrict, char ** __restrict, int); | |
44a09dd6 | 126 | #endif |
5d0641a4 | 127 | int system(const char *); |
5baeefc7 | 128 | int wctomb(char *, wchar_t); |
5d0641a4 PA |
129 | size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); |
130 | ||
131 | /* | |
132 | * Functions added in C99 which we make conditionally available in the | |
133 | * BSD^C89 namespace if the compiler supports `long long'. | |
134 | * The #if test is more complicated than it ought to be because | |
135 | * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' | |
136 | * is not supported in the compilation environment (which therefore means | |
137 | * that it can't really be ISO C99). | |
138 | * | |
139 | * (The only other extension made by C99 in this header is _Exit().) | |
140 | */ | |
b345f56c | 141 | #if __ISO_C_VISIBLE >= 1999 || defined(__cplusplus) |
5d0641a4 PA |
142 | #ifdef __LONG_LONG_SUPPORTED |
143 | /* LONGLONG */ | |
144 | typedef struct { | |
145 | long long quot; | |
146 | long long rem; | |
147 | } lldiv_t; | |
984263bc | 148 | |
5d0641a4 PA |
149 | /* LONGLONG */ |
150 | long long | |
151 | atoll(const char *); | |
152 | /* LONGLONG */ | |
153 | long long | |
154 | llabs(long long) __pure2; | |
155 | /* LONGLONG */ | |
156 | lldiv_t lldiv(long long, long long) __pure2; | |
157 | /* LONGLONG */ | |
158 | long long | |
159 | strtoll(const char * __restrict, char ** __restrict, int); | |
160 | /* LONGLONG */ | |
161 | unsigned long long | |
162 | strtoull(const char * __restrict, char ** __restrict, int); | |
163 | #endif /* __LONG_LONG_SUPPORTED */ | |
164 | ||
165 | void _Exit(int) __dead2; | |
166 | #endif /* __ISO_C_VISIBLE >= 1999 */ | |
167 | ||
d8de7723 | 168 | /* |
169 | * C11 functions. | |
170 | */ | |
1e3ed379 | 171 | #if __ISO_C_VISIBLE >= 2011 || (defined(__cplusplus) && __cplusplus >= 201103L) |
3d258b72 | 172 | void *aligned_alloc(size_t, size_t) __malloclike __heedresult |
173 | __alloc_align(1) __alloc_size(2); | |
174 | int at_quick_exit(void (*)(void)); /* extra extern case for __cplusplus? */ | |
175 | void quick_exit(int) __dead2; | |
d8de7723 | 176 | #endif /* __ISO_C_VISIBLE >= 2011 */ |
177 | ||
5d0641a4 | 178 | /* |
d6fa034f | 179 | * Extensions made by POSIX relative to C. |
5d0641a4 | 180 | */ |
d6fa034f | 181 | #if __POSIX_VISIBLE >= 199506 |
5d0641a4 | 182 | int rand_r(unsigned *); /* (TSF) */ |
d6fa034f | 183 | #endif |
184 | #if __POSIX_VISIBLE >= 200112 | |
3d258b72 | 185 | int posix_memalign(void **, size_t, size_t) __nonnull(1); /* (ADV) */ |
5baeefc7 | 186 | int setenv(const char *, const char *, int); |
5d0641a4 PA |
187 | int unsetenv(const char *); |
188 | #endif | |
5baeefc7 | 189 | |
3b63b459 SW |
190 | #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE |
191 | int getsubopt(char **, char *const *, char **); | |
330f6769 SW |
192 | #ifndef _MKDTEMP_DECLARED |
193 | char *mkdtemp(char *); | |
194 | #define _MKDTEMP_DECLARED | |
195 | #endif | |
196 | #ifndef _MKSTEMP_DECLARED | |
197 | int mkstemp(char *); | |
198 | #define _MKSTEMP_DECLARED | |
199 | #endif | |
200 | #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ | |
201 | ||
5d0641a4 PA |
202 | /* |
203 | * The only changes to the XSI namespace in revision 6 were the deletion | |
204 | * of the ttyslot() and valloc() functions, which we never declared | |
205 | * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which | |
206 | * we also do not have, and mktemp(), are to be deleted. | |
207 | */ | |
208 | #if __XSI_VISIBLE | |
209 | /* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ | |
210 | long a64l(const char *); | |
5baeefc7 JS |
211 | double drand48(void); |
212 | double erand48(unsigned short[3]); | |
f709978f | 213 | #if 0 |
f85b95dd | 214 | #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 700) |
f709978f SW |
215 | char *ecvt(double, int, int * __restrict, int * __restrict); /* LEGACY */ |
216 | char *fcvt(double, int, int * __restrict, int * __restrict); /* LEGACY */ | |
217 | char *gcvt(double, int, int * __restrict, int * __restrict); /* LEGACY */ | |
218 | #endif | |
219 | #endif | |
c578a286 | 220 | int grantpt(int); |
5d0641a4 | 221 | char *initstate(unsigned long /* XSI requires u_int */, char *, long); |
5baeefc7 | 222 | long jrand48(unsigned short[3]); |
5d0641a4 | 223 | char *l64a(long); |
5baeefc7 JS |
224 | void lcong48(unsigned short[7]); |
225 | long lrand48(void); | |
f85b95dd SW |
226 | #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 700) |
227 | #if !defined(_MKTEMP_DECLARED) | |
f709978f | 228 | char *mktemp(char *); /* LEGACY */ |
330f6769 SW |
229 | #define _MKTEMP_DECLARED |
230 | #endif | |
f85b95dd | 231 | #endif |
5baeefc7 JS |
232 | long mrand48(void); |
233 | long nrand48(unsigned short[3]); | |
c578a286 AH |
234 | int posix_openpt(int); |
235 | char *ptsname(int); | |
5d0641a4 PA |
236 | int putenv(char *); |
237 | long random(void); | |
dcd5dd2e | 238 | char *realpath(const char * __restrict, char * __restrict); |
5d0641a4 PA |
239 | unsigned short |
240 | *seed48(unsigned short[3]); | |
241 | int setkey(const char *); | |
242 | char *setstate(/* const */ char *); | |
5baeefc7 | 243 | void srand48(long); |
5d0641a4 | 244 | void srandom(unsigned long); |
c578a286 | 245 | int unlockpt(int); |
5d0641a4 | 246 | #endif /* __XSI_VISIBLE */ |
5baeefc7 | 247 | |
5d0641a4 PA |
248 | #if __BSD_VISIBLE |
249 | /* extern const char *_malloc_options; | |
250 | extern void (*_malloc_message)(const char *, const char *, const char *, | |
251 | const char *); */ | |
252 | ||
253 | /* | |
254 | * The alloca() function can't be implemented in C, and on some | |
255 | * platforms it can't be implemented at all as a callable function. | |
b6e3710e SW |
256 | * The GNU C compiler provides a built-in alloca() which we can use. |
257 | * On platforms where alloca() is not in libc, programs which use it | |
258 | * will fail to link when compiled with non-GNU compilers. | |
5d0641a4 | 259 | */ |
c78f0d6a | 260 | #if __GNUC__ >= 2 |
5d0641a4 PA |
261 | #undef alloca /* some GNU bits try to get cute and define this on their own */ |
262 | #define alloca(sz) __builtin_alloca(sz) | |
5d0641a4 PA |
263 | #endif |
264 | ||
265 | __uint32_t | |
266 | arc4random(void); | |
d82b6b65 | 267 | void arc4random_addrandom(__uint8_t *, size_t); |
5d0641a4 | 268 | void arc4random_buf(void *, size_t); |
5baeefc7 | 269 | void arc4random_stir(void); |
5d0641a4 PA |
270 | __uint32_t |
271 | arc4random_uniform(__uint32_t); | |
5baeefc7 | 272 | char *getbsize(int *, long *); |
f736c3f8 SW |
273 | |
274 | /* getcap(3) functions */ | |
6a7eb1f6 | 275 | char *cgetcap(char *, const char *, int); |
5baeefc7 | 276 | int cgetclose(void); |
6a7eb1f6 | 277 | int cgetent(char **, char **, const char *); |
5baeefc7 | 278 | int cgetfirst(char **, char **); |
6a7eb1f6 | 279 | int cgetmatch(const char *, const char *); |
5baeefc7 | 280 | int cgetnext(char **, char **); |
6a7eb1f6 PA |
281 | int cgetnum(char *, const char *, long *); |
282 | int cgetset(const char *); | |
283 | int cgetstr(char *, const char *, char **); | |
284 | int cgetustr(char *, const char *, char **); | |
5baeefc7 | 285 | |
7307c476 | 286 | int clearenv(void); |
5baeefc7 | 287 | int daemon(int, int); |
24d00e84 JS |
288 | char *devname(dev_t, mode_t); |
289 | char *devname_r(dev_t, mode_t, char *, size_t); | |
f736c3f8 SW |
290 | char *fdevname(int); |
291 | int fdevname_r(int, char *, size_t); | |
78297c9b | 292 | void freezero(void *, size_t); |
3eaaad2c | 293 | int getloadavg(double [], int); |
b27f3669 | 294 | const char * |
5d0641a4 | 295 | getprogname(void); |
5baeefc7 | 296 | |
5baeefc7 | 297 | int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); |
5d0641a4 | 298 | int l64a_r(long, char *, int); |
5baeefc7 | 299 | int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); |
5270936c MD |
300 | int mkostemp(char *, int); |
301 | int mkostemps(char *, int, int); | |
5d0641a4 PA |
302 | void qsort_r(void *, size_t, size_t, void *, |
303 | int (*)(void *, const void *, const void *)); | |
5baeefc7 JS |
304 | int radixsort(const unsigned char **, int, const unsigned char *, |
305 | unsigned int); | |
66932323 | 306 | void *reallocarray(void *, size_t, size_t) __heedresult __alloc_size2(2, 3); |
64c3fdb4 | 307 | void *recallocarray(void *, size_t, size_t, size_t) __heedresult |
308 | __alloc_size2(3, 4); | |
3d258b72 | 309 | void *reallocf(void *, size_t) __heedresult __alloc_size(2); |
5d0641a4 | 310 | int rpmatch(const char *); |
5baeefc7 | 311 | void setprogname(const char *); |
5d0641a4 PA |
312 | int sradixsort(const unsigned char **, int, const unsigned char *, |
313 | unsigned int); | |
314 | void sranddev(void); | |
5baeefc7 | 315 | void srandomdev(void); |
e6975a4e SW |
316 | long long |
317 | strsuftoll(const char *, const char *, long long, long long); | |
318 | long long | |
319 | strsuftollx(const char *, const char *, long long, long long, char *, | |
320 | size_t); | |
5d0641a4 | 321 | long long |
f736c3f8 | 322 | strtonum(const char *, long long, long long, const char **); |
44a09dd6 | 323 | |
5d0641a4 PA |
324 | /* Deprecated interfaces. */ |
325 | #if !defined(_KERNEL_VIRTUAL) | |
326 | __int64_t | |
327 | strtoq(const char *, char **, int); | |
328 | __uint64_t | |
329 | strtouq(const char *, char **, int); | |
44a09dd6 | 330 | #endif |
70e9d14e | 331 | |
5d0641a4 PA |
332 | extern char *suboptarg; /* getsubopt(3) external variable */ |
333 | #endif /* __BSD_VISIBLE */ | |
086b156c SW |
334 | |
335 | #if __EXT1_VISIBLE | |
336 | /* K.3.6 */ | |
337 | typedef void (*constraint_handler_t)(const char * __restrict, | |
338 | void * __restrict, errno_t); | |
339 | /* K.3.6.1.1 */ | |
340 | constraint_handler_t set_constraint_handler_s(constraint_handler_t handler); | |
341 | /* K.3.6.1.2 */ | |
342 | _Noreturn void abort_handler_s(const char * __restrict, void * __restrict, | |
343 | errno_t); | |
344 | /* K3.6.1.3 */ | |
345 | void ignore_handler_s(const char * __restrict, void * __restrict, errno_t); | |
346 | #endif /* __EXT1_VISIBLE */ | |
984263bc MD |
347 | __END_DECLS |
348 | ||
349 | #endif /* !_STDLIB_H_ */ |