| 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. | |
| 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. | |
| 20 | * | |
| 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 | |
| 31 | * SUCH DAMAGE. | |
| 32 | * | |
| 33 | * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 | |
| 5d0641a4 | 34 | * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $ |
| 984263bc MD |
35 | */ |
| 36 | ||
| 37 | #ifndef _STDLIB_H_ | |
| 38 | #define _STDLIB_H_ | |
| 39 | ||
| 40 | #include <sys/cdefs.h> | |
| 5d0641a4 | 41 | #include <sys/_null.h> |
| fa261b1d | 42 | #include <sys/types.h> |
| 984263bc | 43 | |
| 5d0641a4 PA |
44 | #ifndef _SIZE_T_DECLARED |
| 45 | typedef __size_t size_t; | |
| 46 | #define _SIZE_T_DECLARED | |
| e2565a42 | 47 | #endif |
| 984263bc | 48 | |
| 5d0641a4 | 49 | #ifndef __cplusplus |
| a81b3ef3 | 50 | #ifndef _WCHAR_T_DECLARED |
| 5d0641a4 PA |
51 | typedef __wchar_t wchar_t; |
| 52 | #define _WCHAR_T_DECLARED | |
| 984263bc | 53 | #endif |
| 984263bc | 54 | #endif |
| e2565a42 | 55 | |
| 984263bc | 56 | typedef struct { |
| 5d0641a4 PA |
57 | int quot; /* quotient */ |
| 58 | int rem; /* remainder */ | |
| 984263bc MD |
59 | } div_t; |
| 60 | ||
| 61 | typedef struct { | |
| 5d0641a4 PA |
62 | long quot; |
| 63 | long rem; | |
| 984263bc MD |
64 | } ldiv_t; |
| 65 | ||
| 984263bc MD |
66 | #define EXIT_FAILURE 1 |
| 67 | #define EXIT_SUCCESS 0 | |
| 68 | ||
| 69 | #define RAND_MAX 0x7fffffff | |
| 70 | ||
| 71 | extern int __mb_cur_max; | |
| 72 | #define MB_CUR_MAX __mb_cur_max | |
| 73 | ||
| 74 | __BEGIN_DECLS | |
| 5baeefc7 | 75 | void abort(void) __dead2; |
| 5d0641a4 | 76 | /* void abort2(const char *, int, void **) __dead2; */ |
| 4d42eed2 | 77 | #if !defined(_KERNEL_VIRTUAL) |
| 5baeefc7 | 78 | int abs(int) __pure2; |
| 4d42eed2 | 79 | #endif |
| 5baeefc7 JS |
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; | |
| 89 | void free(void *); | |
| 90 | char *getenv(const char *); | |
| 4d42eed2 | 91 | #if !defined(_KERNEL_VIRTUAL) |
| 5baeefc7 | 92 | long labs(long) __pure2; |
| 4d42eed2 | 93 | #endif |
| 5baeefc7 JS |
94 | ldiv_t ldiv(long, long) __pure2; |
| 95 | void *malloc(size_t); | |
| 11e45f67 | 96 | int posix_memalign(void **, size_t, size_t); |
| 5d0641a4 PA |
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 *)); | |
| 5baeefc7 JS |
101 | int rand(void); |
| 102 | void *realloc(void *, size_t); | |
| 103 | void srand(unsigned); | |
| 5d0641a4 | 104 | double strtod(const char * __restrict, char ** __restrict); |
| f202adf7 | 105 | float strtof(const char * __restrict, char ** __restrict); |
| 5d0641a4 PA |
106 | #if !defined(_KERNEL_VIRTUAL) |
| 107 | long strtol(const char * __restrict, char ** __restrict, int); | |
| 984263bc | 108 | #endif |
| f202adf7 PA |
109 | long double |
| 110 | strtold(const char * __restrict, char ** __restrict); | |
| 44a09dd6 | 111 | #if !defined(_KERNEL_VIRTUAL) |
| 5d0641a4 PA |
112 | unsigned long |
| 113 | strtoul(const char * __restrict, char ** __restrict, int); | |
| 44a09dd6 | 114 | #endif |
| 5d0641a4 | 115 | int system(const char *); |
| 5baeefc7 | 116 | int wctomb(char *, wchar_t); |
| 5d0641a4 PA |
117 | size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); |
| 118 | ||
| 119 | /* | |
| 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). | |
| 126 | * | |
| 127 | * (The only other extension made by C99 in this header is _Exit().) | |
| 128 | */ | |
| 129 | #if __ISO_C_VISIBLE >= 1999 | |
| 130 | #ifdef __LONG_LONG_SUPPORTED | |
| 131 | /* LONGLONG */ | |
| 132 | typedef struct { | |
| 133 | long long quot; | |
| 134 | long long rem; | |
| 135 | } lldiv_t; | |
| 984263bc | 136 | |
| 5d0641a4 PA |
137 | /* LONGLONG */ |
| 138 | long long | |
| 139 | atoll(const char *); | |
| 140 | /* LONGLONG */ | |
| 141 | long long | |
| 142 | llabs(long long) __pure2; | |
| 143 | /* LONGLONG */ | |
| 144 | lldiv_t lldiv(long long, long long) __pure2; | |
| 145 | /* LONGLONG */ | |
| 146 | long long | |
| 147 | strtoll(const char * __restrict, char ** __restrict, int); | |
| 148 | /* LONGLONG */ | |
| 149 | unsigned long long | |
| 150 | strtoull(const char * __restrict, char ** __restrict, int); | |
| 151 | #endif /* __LONG_LONG_SUPPORTED */ | |
| 152 | ||
| 153 | void _Exit(int) __dead2; | |
| 154 | #endif /* __ISO_C_VISIBLE >= 1999 */ | |
| 155 | ||
| 156 | /* | |
| 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. | |
| 160 | */ | |
| 161 | #if __POSIX_VISIBLE /* >= ??? */ | |
| 162 | /*int posix_memalign(void **, size_t, size_t); (ADV) */ | |
| 163 | int rand_r(unsigned *); /* (TSF) */ | |
| 5baeefc7 | 164 | int setenv(const char *, const char *, int); |
| 5d0641a4 PA |
165 | int unsetenv(const char *); |
| 166 | #endif | |
| 5baeefc7 | 167 | |
| 330f6769 SW |
168 | #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE |
| 169 | #ifndef _MKDTEMP_DECLARED | |
| 170 | char *mkdtemp(char *); | |
| 171 | #define _MKDTEMP_DECLARED | |
| 172 | #endif | |
| 173 | #ifndef _MKSTEMP_DECLARED | |
| 174 | int mkstemp(char *); | |
| 175 | #define _MKSTEMP_DECLARED | |
| 176 | #endif | |
| 177 | #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ | |
| 178 | ||
| 5d0641a4 PA |
179 | /* |
| 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. | |
| 184 | */ | |
| 185 | #if __XSI_VISIBLE | |
| 186 | /* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ | |
| 187 | long a64l(const char *); | |
| 5baeefc7 | 188 | double drand48(void); |
| 5d0641a4 | 189 | /* char *ecvt(double, int, int * __restrict, int * __restrict); */ |
| 5baeefc7 | 190 | double erand48(unsigned short[3]); |
| 5d0641a4 PA |
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 **); | |
| c578a286 | 194 | int grantpt(int); |
| 5d0641a4 | 195 | char *initstate(unsigned long /* XSI requires u_int */, char *, long); |
| 5baeefc7 | 196 | long jrand48(unsigned short[3]); |
| 5d0641a4 | 197 | char *l64a(long); |
| 5baeefc7 JS |
198 | void lcong48(unsigned short[7]); |
| 199 | long lrand48(void); | |
| 330f6769 SW |
200 | #if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600) |
| 201 | char *mktemp(char *); | |
| 202 | #define _MKTEMP_DECLARED | |
| 203 | #endif | |
| 5baeefc7 JS |
204 | long mrand48(void); |
| 205 | long nrand48(unsigned short[3]); | |
| c578a286 AH |
206 | int posix_openpt(int); |
| 207 | char *ptsname(int); | |
| 5d0641a4 PA |
208 | int putenv(char *); |
| 209 | long random(void); | |
| dcd5dd2e | 210 | char *realpath(const char * __restrict, char * __restrict); |
| 5d0641a4 PA |
211 | unsigned short |
| 212 | *seed48(unsigned short[3]); | |
| 213 | int setkey(const char *); | |
| 214 | char *setstate(/* const */ char *); | |
| 5baeefc7 | 215 | void srand48(long); |
| 5d0641a4 | 216 | void srandom(unsigned long); |
| c578a286 | 217 | int unlockpt(int); |
| 5d0641a4 | 218 | #endif /* __XSI_VISIBLE */ |
| 5baeefc7 | 219 | |
| 5d0641a4 PA |
220 | #if __BSD_VISIBLE |
| 221 | /* extern const char *_malloc_options; | |
| 222 | extern void (*_malloc_message)(const char *, const char *, const char *, | |
| 223 | const char *); */ | |
| 224 | ||
| 225 | /* | |
| 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 | |
| 232 | * compilers. | |
| 233 | */ | |
| 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) | |
| 237 | #elif defined(lint) | |
| 238 | void *alloca(size_t); | |
| 239 | #endif | |
| 240 | ||
| 241 | __uint32_t | |
| 242 | arc4random(void); | |
| d82b6b65 | 243 | void arc4random_addrandom(__uint8_t *, size_t); |
| 5d0641a4 | 244 | void arc4random_buf(void *, size_t); |
| 5baeefc7 | 245 | void arc4random_stir(void); |
| 5d0641a4 PA |
246 | __uint32_t |
| 247 | arc4random_uniform(__uint32_t); | |
| 5baeefc7 | 248 | char *getbsize(int *, long *); |
| f736c3f8 SW |
249 | |
| 250 | /* getcap(3) functions */ | |
| 6a7eb1f6 | 251 | char *cgetcap(char *, const char *, int); |
| 5baeefc7 | 252 | int cgetclose(void); |
| 6a7eb1f6 | 253 | int cgetent(char **, char **, const char *); |
| 5baeefc7 | 254 | int cgetfirst(char **, char **); |
| 6a7eb1f6 | 255 | int cgetmatch(const char *, const char *); |
| 5baeefc7 | 256 | int cgetnext(char **, char **); |
| 6a7eb1f6 PA |
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 **); | |
| 5baeefc7 JS |
261 | |
| 262 | int daemon(int, int); | |
| 24d00e84 JS |
263 | char *devname(dev_t, mode_t); |
| 264 | char *devname_r(dev_t, mode_t, char *, size_t); | |
| f736c3f8 SW |
265 | char *fdevname(int); |
| 266 | int fdevname_r(int, char *, size_t); | |
| 3eaaad2c | 267 | int getloadavg(double [], int); |
| b27f3669 | 268 | const char * |
| 5d0641a4 | 269 | getprogname(void); |
| 5baeefc7 | 270 | |
| 5baeefc7 | 271 | int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); |
| 5d0641a4 | 272 | int l64a_r(long, char *, int); |
| 5baeefc7 | 273 | int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); |
| 5d0641a4 PA |
274 | void qsort_r(void *, size_t, size_t, void *, |
| 275 | int (*)(void *, const void *, const void *)); | |
| 5baeefc7 JS |
276 | int radixsort(const unsigned char **, int, const unsigned char *, |
| 277 | unsigned int); | |
| 5baeefc7 | 278 | void *reallocf(void *, size_t); |
| 5d0641a4 | 279 | int rpmatch(const char *); |
| 5baeefc7 | 280 | void setprogname(const char *); |
| 5d0641a4 PA |
281 | int sradixsort(const unsigned char **, int, const unsigned char *, |
| 282 | unsigned int); | |
| 283 | void sranddev(void); | |
| 5baeefc7 | 284 | void srandomdev(void); |
| 5d0641a4 | 285 | long long |
| f736c3f8 | 286 | strtonum(const char *, long long, long long, const char **); |
| 44a09dd6 | 287 | |
| 5d0641a4 PA |
288 | /* Deprecated interfaces. */ |
| 289 | #if !defined(_KERNEL_VIRTUAL) | |
| 290 | __int64_t | |
| 291 | strtoq(const char *, char **, int); | |
| 292 | __uint64_t | |
| 293 | strtouq(const char *, char **, int); | |
| 44a09dd6 | 294 | #endif |
| 70e9d14e | 295 | |
| 5d0641a4 PA |
296 | extern char *suboptarg; /* getsubopt(3) external variable */ |
| 297 | #endif /* __BSD_VISIBLE */ | |
| b8b8fcfe SW |
298 | |
| 299 | /* | |
| 300 | * C11 functions. | |
| 301 | */ | |
| 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 */ | |
| 307 | ||
| 984263bc MD |
308 | __END_DECLS |
| 309 | ||
| 310 | #endif /* !_STDLIB_H_ */ |