159deaec5SRodney W. Grimes /*- 259deaec5SRodney W. Grimes * Copyright (c) 1990, 1993 359deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 459deaec5SRodney W. Grimes * 559deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 659deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 759deaec5SRodney W. Grimes * are met: 859deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 959deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1059deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1159deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1259deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 1359deaec5SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 1459deaec5SRodney W. Grimes * must display the following acknowledgement: 1559deaec5SRodney W. Grimes * This product includes software developed by the University of 1659deaec5SRodney W. Grimes * California, Berkeley and its contributors. 1759deaec5SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 1859deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 1959deaec5SRodney W. Grimes * without specific prior written permission. 2059deaec5SRodney W. Grimes * 2159deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159deaec5SRodney W. Grimes * SUCH DAMAGE. 3259deaec5SRodney W. Grimes * 33c59376afSPeter Wemm * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 34dea750aeSBruce Evans * $FreeBSD$ 3559deaec5SRodney W. Grimes */ 3659deaec5SRodney W. Grimes 3759deaec5SRodney W. Grimes #ifndef _STDLIB_H_ 3859deaec5SRodney W. Grimes #define _STDLIB_H_ 3959deaec5SRodney W. Grimes 4085b46962SBruce Evans #include <sys/cdefs.h> 4112eb46c8SMarcel Moolenaar #include <sys/_null.h> 42abbd8902SMike Barcroft #include <sys/_types.h> 4359deaec5SRodney W. Grimes 443ecc48e2SGarrett Wollman #if __BSD_VISIBLE 45abbd8902SMike Barcroft #ifndef _RUNE_T_DECLARED 46abbd8902SMike Barcroft typedef __rune_t rune_t; 47abbd8902SMike Barcroft #define _RUNE_T_DECLARED 48cdd84b02SBruce Evans #endif 49cdd84b02SBruce Evans #endif 50cdd84b02SBruce Evans 51abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 52abbd8902SMike Barcroft typedef __size_t size_t; 53abbd8902SMike Barcroft #define _SIZE_T_DECLARED 5459deaec5SRodney W. Grimes #endif 5559deaec5SRodney W. Grimes 566087d244SDavid E. O'Brien #ifndef __cplusplus 57abbd8902SMike Barcroft #ifndef _WCHAR_T_DECLARED 58abbd8902SMike Barcroft typedef __wchar_t wchar_t; 59abbd8902SMike Barcroft #define _WCHAR_T_DECLARED 6059deaec5SRodney W. Grimes #endif 616087d244SDavid E. O'Brien #endif 6259deaec5SRodney W. Grimes 6359deaec5SRodney W. Grimes typedef struct { 6459deaec5SRodney W. Grimes int quot; /* quotient */ 6559deaec5SRodney W. Grimes int rem; /* remainder */ 6659deaec5SRodney W. Grimes } div_t; 6759deaec5SRodney W. Grimes 6859deaec5SRodney W. Grimes typedef struct { 69a4c8a68cSBruce Evans long quot; 70a4c8a68cSBruce Evans long rem; 7159deaec5SRodney W. Grimes } ldiv_t; 7259deaec5SRodney W. Grimes 7359deaec5SRodney W. Grimes #define EXIT_FAILURE 1 7459deaec5SRodney W. Grimes #define EXIT_SUCCESS 0 7559deaec5SRodney W. Grimes 7659deaec5SRodney W. Grimes #define RAND_MAX 0x7fffffff 7759deaec5SRodney W. Grimes 7859deaec5SRodney W. Grimes extern int __mb_cur_max; 7959deaec5SRodney W. Grimes #define MB_CUR_MAX __mb_cur_max 8059deaec5SRodney W. Grimes 8159deaec5SRodney W. Grimes __BEGIN_DECLS 82bb28f3c2SWarner Losh void abort(void) __dead2; 83bb28f3c2SWarner Losh int abs(int) __pure2; 84bb28f3c2SWarner Losh int atexit(void (*)(void)); 85bb28f3c2SWarner Losh double atof(const char *); 86bb28f3c2SWarner Losh int atoi(const char *); 87bb28f3c2SWarner Losh long atol(const char *); 88bb28f3c2SWarner Losh void *bsearch(const void *, const void *, size_t, 89bb28f3c2SWarner Losh size_t, int (*)(const void *, const void *)); 90544048ecSDavid Schultz void *calloc(size_t, size_t) __malloc_like; 91bb28f3c2SWarner Losh div_t div(int, int) __pure2; 92bb28f3c2SWarner Losh void exit(int) __dead2; 93bb28f3c2SWarner Losh void free(void *); 94bb28f3c2SWarner Losh char *getenv(const char *); 95bb28f3c2SWarner Losh long labs(long) __pure2; 96bb28f3c2SWarner Losh ldiv_t ldiv(long, long) __pure2; 97544048ecSDavid Schultz void *malloc(size_t) __malloc_like; 983ecc48e2SGarrett Wollman int mblen(const char *, size_t); 993ecc48e2SGarrett Wollman size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 1003ecc48e2SGarrett Wollman int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 101bb28f3c2SWarner Losh void qsort(void *, size_t, size_t, 102bb28f3c2SWarner Losh int (*)(const void *, const void *)); 103bb28f3c2SWarner Losh int rand(void); 104bb28f3c2SWarner Losh void *realloc(void *, size_t); 105bb28f3c2SWarner Losh void srand(unsigned); 1065618f724SRobert Drehmel double strtod(const char * __restrict, char ** __restrict); 1076a66acb5SDavid Schultz float strtof(const char * __restrict, char ** __restrict); 1085618f724SRobert Drehmel long strtol(const char * __restrict, char ** __restrict, int); 1096a66acb5SDavid Schultz long double 1106a66acb5SDavid Schultz strtold(const char * __restrict, char ** __restrict); 11159deaec5SRodney W. Grimes unsigned long 1125618f724SRobert Drehmel strtoul(const char * __restrict, char ** __restrict, int); 113bb28f3c2SWarner Losh int system(const char *); 114bb28f3c2SWarner Losh int wctomb(char *, wchar_t); 1159771f1e2STim J. Robbins size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 11659deaec5SRodney W. Grimes 1173ecc48e2SGarrett Wollman /* 1183ecc48e2SGarrett Wollman * Functions added in C99 which we make conditionally available in the 1193ecc48e2SGarrett Wollman * BSD^C89 namespace if the compiler supports `long long'. 1203ecc48e2SGarrett Wollman * The #if test is more complicated than it ought to be because 1213ecc48e2SGarrett Wollman * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 1223ecc48e2SGarrett Wollman * is not supported in the compilation environment (which therefore means 1233ecc48e2SGarrett Wollman * that it can't really be ISO C99). 1243ecc48e2SGarrett Wollman * 1253ecc48e2SGarrett Wollman * (The only other extension made by C99 in thie header is _Exit().) 1263ecc48e2SGarrett Wollman */ 1273ecc48e2SGarrett Wollman #if __ISO_C_VISIBLE >= 1999 1283ecc48e2SGarrett Wollman #ifdef __LONG_LONG_SUPPORTED 1293ecc48e2SGarrett Wollman /* LONGLONG */ 1303ecc48e2SGarrett Wollman typedef struct { 1313ecc48e2SGarrett Wollman long long quot; 1323ecc48e2SGarrett Wollman long long rem; 1333ecc48e2SGarrett Wollman } lldiv_t; 134798c1fd8SPoul-Henning Kamp 1353ecc48e2SGarrett Wollman /* LONGLONG */ 1363ecc48e2SGarrett Wollman long long 1373ecc48e2SGarrett Wollman atoll(const char *); 1383ecc48e2SGarrett Wollman /* LONGLONG */ 1393ecc48e2SGarrett Wollman long long 1403ecc48e2SGarrett Wollman llabs(long long) __pure2; 1413ecc48e2SGarrett Wollman /* LONGLONG */ 1423ecc48e2SGarrett Wollman lldiv_t lldiv(long long, long long) __pure2; 1433ecc48e2SGarrett Wollman /* LONGLONG */ 1443ecc48e2SGarrett Wollman long long 1453ecc48e2SGarrett Wollman strtoll(const char * __restrict, char ** __restrict, int); 1463ecc48e2SGarrett Wollman /* LONGLONG */ 1473ecc48e2SGarrett Wollman unsigned long long 1483ecc48e2SGarrett Wollman strtoull(const char * __restrict, char ** __restrict, int); 1493ecc48e2SGarrett Wollman #endif /* __LONG_LONG_SUPPORTED */ 1503ecc48e2SGarrett Wollman 1513ecc48e2SGarrett Wollman void _Exit(int) __dead2; 1523ecc48e2SGarrett Wollman #endif /* __ISO_C_VISIBLE >= 1999 */ 1533ecc48e2SGarrett Wollman 1543ecc48e2SGarrett Wollman /* 1553ecc48e2SGarrett Wollman * Extensions made by POSIX relative to C. We don't know yet which edition 1563ecc48e2SGarrett Wollman * of POSIX made these extensions, so assume they've always been there until 1573ecc48e2SGarrett Wollman * research can be done. 1583ecc48e2SGarrett Wollman */ 1593ecc48e2SGarrett Wollman #if __POSIX_VISIBLE /* >= ??? */ 160b3d51d3aSJason Evans int posix_memalign(void **, size_t, size_t); /* (ADV) */ 1613ecc48e2SGarrett Wollman int rand_r(unsigned *); /* (TSF) */ 162bb28f3c2SWarner Losh int setenv(const char *, const char *, int); 1632966d28cSSean Farley int unsetenv(const char *); 1643ecc48e2SGarrett Wollman #endif 16559deaec5SRodney W. Grimes 16665e8b129SDavid Schultz #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE 16765e8b129SDavid Schultz int getsubopt(char **, char *const *, char **); 16865e8b129SDavid Schultz #ifndef _MKDTEMP_DECLARED 16965e8b129SDavid Schultz char *mkdtemp(char *); 17065e8b129SDavid Schultz #define _MKDTEMP_DECLARED 17165e8b129SDavid Schultz #endif 17265e8b129SDavid Schultz #ifndef _MKSTEMP_DECLARED 17365e8b129SDavid Schultz int mkstemp(char *); 17465e8b129SDavid Schultz #define _MKSTEMP_DECLARED 17565e8b129SDavid Schultz #endif 17665e8b129SDavid Schultz #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ 17765e8b129SDavid Schultz 1783ecc48e2SGarrett Wollman /* 1793ecc48e2SGarrett Wollman * The only changes to the XSI namespace in revision 6 were the deletion 1803ecc48e2SGarrett Wollman * of the ttyslot() and valloc() functions, which FreeBSD never declared 1813ecc48e2SGarrett Wollman * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 1823ecc48e2SGarrett Wollman * FreeBSD also does not have, and mktemp(), are to be deleted. 1833ecc48e2SGarrett Wollman */ 1843ecc48e2SGarrett Wollman #if __XSI_VISIBLE 1853ecc48e2SGarrett Wollman /* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 186257551c6STom Rhodes long a64l(const char *); 187bb28f3c2SWarner Losh double drand48(void); 1883ecc48e2SGarrett Wollman /* char *ecvt(double, int, int * __restrict, int * __restrict); */ 189bb28f3c2SWarner Losh double erand48(unsigned short[3]); 1903ecc48e2SGarrett Wollman /* char *fcvt(double, int, int * __restrict, int * __restrict); */ 1913ecc48e2SGarrett Wollman /* char *gcvt(double, int, int * __restrict, int * __restrict); */ 192d3951ad1SJuli Mallett int grantpt(int); 1933ecc48e2SGarrett Wollman char *initstate(unsigned long /* XSI requires u_int */, char *, long); 194bb28f3c2SWarner Losh long jrand48(unsigned short[3]); 195257551c6STom Rhodes char *l64a(long); 196bb28f3c2SWarner Losh void lcong48(unsigned short[7]); 197bb28f3c2SWarner Losh long lrand48(void); 198d9c43159SDavid Schultz #if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600) 1993ecc48e2SGarrett Wollman char *mktemp(char *); 2003ecc48e2SGarrett Wollman #define _MKTEMP_DECLARED 2013ecc48e2SGarrett Wollman #endif 202bb28f3c2SWarner Losh long mrand48(void); 203bb28f3c2SWarner Losh long nrand48(unsigned short[3]); 204d3951ad1SJuli Mallett int posix_openpt(int); 205d3951ad1SJuli Mallett char *ptsname(int); 2062966d28cSSean Farley int putenv(char *); 2073ecc48e2SGarrett Wollman long random(void); 2083ecc48e2SGarrett Wollman char *realpath(const char *, char resolved_path[]); 20967c54240SBruce Evans unsigned short 210bb28f3c2SWarner Losh *seed48(unsigned short[3]); 2113ecc48e2SGarrett Wollman #ifndef _SETKEY_DECLARED 2123ecc48e2SGarrett Wollman int setkey(const char *); 2133ecc48e2SGarrett Wollman #define _SETKEY_DECLARED 2143ecc48e2SGarrett Wollman #endif 2153ecc48e2SGarrett Wollman char *setstate(/* const */ char *); 216bb28f3c2SWarner Losh void srand48(long); 2173ecc48e2SGarrett Wollman void srandom(unsigned long); 218d3951ad1SJuli Mallett int unlockpt(int); 2193ecc48e2SGarrett Wollman #endif /* __XSI_VISIBLE */ 2203ecc48e2SGarrett Wollman 2213ecc48e2SGarrett Wollman #if __BSD_VISIBLE 2223ecc48e2SGarrett Wollman extern const char *_malloc_options; 223a4c8a68cSBruce Evans extern void (*_malloc_message)(const char *, const char *, const char *, 224a4c8a68cSBruce Evans const char *); 225f8f6d0dcSAndreas Schulz 22679806b4cSDag-Erling Smørgrav /* 22779806b4cSDag-Erling Smørgrav * The alloca() function can't be implemented in C, and on some 22879806b4cSDag-Erling Smørgrav * platforms it can't be implemented at all as a callable function. 22979806b4cSDag-Erling Smørgrav * The GNU C compiler provides a built-in alloca() which we can use; 23079806b4cSDag-Erling Smørgrav * in all other cases, provide a prototype, mainly to pacify various 23179806b4cSDag-Erling Smørgrav * incarnations of lint. On platforms where alloca() is not in libc, 23279806b4cSDag-Erling Smørgrav * programs which use it will fail to link when compiled with non-GNU 23379806b4cSDag-Erling Smørgrav * compilers. 23479806b4cSDag-Erling Smørgrav */ 235d7875fc3SDavid E. O'Brien #if __GNUC__ >= 2 || defined(__INTEL_COMPILER) 236d7875fc3SDavid E. O'Brien #undef alloca /* some GNU bits try to get cute and define this on their own */ 23779806b4cSDag-Erling Smørgrav #define alloca(sz) __builtin_alloca(sz) 238d7875fc3SDavid E. O'Brien #elif defined(lint) 23979806b4cSDag-Erling Smørgrav void *alloca(size_t); 24079806b4cSDag-Erling Smørgrav #endif 24179806b4cSDag-Erling Smørgrav 242b38a55d4SDavid Schultz void abort2(const char *, int, void **) __dead2; 2438252a465SDmitrij Tejblum __uint32_t 244bb28f3c2SWarner Losh arc4random(void); 2453204108bSAndrey A. Chernov void arc4random_addrandom(unsigned char *, int); 2463204108bSAndrey A. Chernov void arc4random_buf(void *, size_t); 247bb28f3c2SWarner Losh void arc4random_stir(void); 248c0046493SAndrey A. Chernov __uint32_t 249c0046493SAndrey A. Chernov arc4random_uniform(__uint32_t); 250c2e55537SDavid E. O'Brien char *getbsize(int *, long *); 2513ecc48e2SGarrett Wollman /* getcap(3) functions */ 252bb28f3c2SWarner Losh char *cgetcap(char *, const char *, int); 253bb28f3c2SWarner Losh int cgetclose(void); 254bb28f3c2SWarner Losh int cgetent(char **, char **, const char *); 255bb28f3c2SWarner Losh int cgetfirst(char **, char **); 256bb28f3c2SWarner Losh int cgetmatch(const char *, const char *); 257bb28f3c2SWarner Losh int cgetnext(char **, char **); 258bb28f3c2SWarner Losh int cgetnum(char *, const char *, long *); 259bb28f3c2SWarner Losh int cgetset(const char *); 260bb28f3c2SWarner Losh int cgetstr(char *, const char *, char **); 261bb28f3c2SWarner Losh int cgetustr(char *, const char *, char **); 26259deaec5SRodney W. Grimes 263bb28f3c2SWarner Losh int daemon(int, int); 2649d301680SStefan Farfeleder char *devname(__dev_t, __mode_t); 2659d301680SStefan Farfeleder char *devname_r(__dev_t, __mode_t, char *, int); 26626d4f5e9SEd Schouten char *fdevname(int); 26726d4f5e9SEd Schouten char *fdevname_r(int, char *, int); 268bb28f3c2SWarner Losh int getloadavg(double [], int); 269ec55a605SMike Barcroft __const char * 270bb28f3c2SWarner Losh getprogname(void); 27159deaec5SRodney W. Grimes 272bb28f3c2SWarner Losh int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 273257551c6STom Rhodes int l64a_r(long, char *, int); 274bb28f3c2SWarner Losh int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 2750855f655SGarrett Wollman void qsort_r(void *, size_t, size_t, void *, 2760855f655SGarrett Wollman int (*)(void *, const void *, const void *)); 277bb28f3c2SWarner Losh int radixsort(const unsigned char **, int, const unsigned char *, 278bb28f3c2SWarner Losh unsigned); 279bb28f3c2SWarner Losh void *reallocf(void *, size_t); 28017ebe400STim J. Robbins int rpmatch(const char *); 281bb28f3c2SWarner Losh void setprogname(const char *); 2820855f655SGarrett Wollman int sradixsort(const unsigned char **, int, const unsigned char *, 2830855f655SGarrett Wollman unsigned); 284bb28f3c2SWarner Losh void sranddev(void); 285bb28f3c2SWarner Losh void srandomdev(void); 286c74dfa2fSAndre Oppermann long long 287c74dfa2fSAndre Oppermann strtonum(const char *, long long, long long, const char **); 2883ecc48e2SGarrett Wollman 2893ecc48e2SGarrett Wollman /* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 290a4c8a68cSBruce Evans __int64_t 291a4c8a68cSBruce Evans strtoq(const char *, char **, int); 2928252a465SDmitrij Tejblum __uint64_t 293bb28f3c2SWarner Losh strtouq(const char *, char **, int); 2948720578dSAndrey A. Chernov 2958720578dSAndrey A. Chernov extern char *suboptarg; /* getsubopt(3) external variable */ 2963ecc48e2SGarrett Wollman #endif /* __BSD_VISIBLE */ 29759deaec5SRodney W. Grimes __END_DECLS 29859deaec5SRodney W. Grimes 29967c54240SBruce Evans #endif /* !_STDLIB_H_ */ 300