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