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> 41abbd8902SMike Barcroft #include <sys/_types.h> 4259deaec5SRodney W. Grimes 433ecc48e2SGarrett Wollman #if __BSD_VISIBLE 44abbd8902SMike Barcroft #ifndef _RUNE_T_DECLARED 45abbd8902SMike Barcroft typedef __rune_t rune_t; 46abbd8902SMike Barcroft #define _RUNE_T_DECLARED 47cdd84b02SBruce Evans #endif 48cdd84b02SBruce Evans #endif 49cdd84b02SBruce Evans 50abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 51abbd8902SMike Barcroft typedef __size_t size_t; 52abbd8902SMike Barcroft #define _SIZE_T_DECLARED 5359deaec5SRodney W. Grimes #endif 5459deaec5SRodney W. Grimes 556087d244SDavid E. O'Brien #ifndef __cplusplus 56abbd8902SMike Barcroft #ifndef _WCHAR_T_DECLARED 57abbd8902SMike Barcroft typedef __wchar_t wchar_t; 58abbd8902SMike Barcroft #define _WCHAR_T_DECLARED 5959deaec5SRodney W. Grimes #endif 606087d244SDavid E. O'Brien #endif 6159deaec5SRodney W. Grimes 6259deaec5SRodney W. Grimes typedef struct { 6359deaec5SRodney W. Grimes int quot; /* quotient */ 6459deaec5SRodney W. Grimes int rem; /* remainder */ 6559deaec5SRodney W. Grimes } div_t; 6659deaec5SRodney W. Grimes 6759deaec5SRodney W. Grimes typedef struct { 68a4c8a68cSBruce Evans long quot; 69a4c8a68cSBruce Evans long rem; 7059deaec5SRodney W. Grimes } ldiv_t; 7159deaec5SRodney W. Grimes 7259deaec5SRodney W. Grimes #ifndef NULL 7359deaec5SRodney W. Grimes #define NULL 0 7459deaec5SRodney W. Grimes #endif 7559deaec5SRodney W. Grimes 7659deaec5SRodney W. Grimes #define EXIT_FAILURE 1 7759deaec5SRodney W. Grimes #define EXIT_SUCCESS 0 7859deaec5SRodney W. Grimes 7959deaec5SRodney W. Grimes #define RAND_MAX 0x7fffffff 8059deaec5SRodney W. Grimes 8159deaec5SRodney W. Grimes extern int __mb_cur_max; 8259deaec5SRodney W. Grimes #define MB_CUR_MAX __mb_cur_max 8359deaec5SRodney W. Grimes 8459deaec5SRodney W. Grimes __BEGIN_DECLS 85bb28f3c2SWarner Losh void abort(void) __dead2; 86bb28f3c2SWarner Losh int abs(int) __pure2; 87bb28f3c2SWarner Losh int atexit(void (*)(void)); 88bb28f3c2SWarner Losh double atof(const char *); 89bb28f3c2SWarner Losh int atoi(const char *); 90bb28f3c2SWarner Losh long atol(const char *); 91bb28f3c2SWarner Losh void *bsearch(const void *, const void *, size_t, 92bb28f3c2SWarner Losh size_t, int (*)(const void *, const void *)); 93bb28f3c2SWarner Losh void *calloc(size_t, size_t); 94bb28f3c2SWarner Losh div_t div(int, int) __pure2; 95bb28f3c2SWarner Losh void exit(int) __dead2; 96bb28f3c2SWarner Losh void free(void *); 97bb28f3c2SWarner Losh char *getenv(const char *); 98bb28f3c2SWarner Losh long labs(long) __pure2; 99bb28f3c2SWarner Losh ldiv_t ldiv(long, long) __pure2; 100bb28f3c2SWarner Losh void *malloc(size_t); 1013ecc48e2SGarrett Wollman int mblen(const char *, size_t); 1023ecc48e2SGarrett Wollman size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 1033ecc48e2SGarrett Wollman int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 104bb28f3c2SWarner Losh void qsort(void *, size_t, size_t, 105bb28f3c2SWarner Losh int (*)(const void *, const void *)); 106bb28f3c2SWarner Losh int rand(void); 107bb28f3c2SWarner Losh void *realloc(void *, size_t); 108bb28f3c2SWarner Losh void srand(unsigned); 1095618f724SRobert Drehmel double strtod(const char * __restrict, char ** __restrict); 1103ecc48e2SGarrett Wollman /* float strtof(const char * __restrict, char ** __restrict); */ 1115618f724SRobert Drehmel long strtol(const char * __restrict, char ** __restrict, int); 1123ecc48e2SGarrett Wollman /* long double 1133ecc48e2SGarrett Wollman strtold(const char * __restrict, char ** __restrict); */ 11459deaec5SRodney W. Grimes unsigned long 1155618f724SRobert Drehmel strtoul(const char * __restrict, char ** __restrict, int); 116bb28f3c2SWarner Losh int system(const char *); 117bb28f3c2SWarner Losh int wctomb(char *, wchar_t); 1189771f1e2STim J. Robbins size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 11959deaec5SRodney W. Grimes 1203ecc48e2SGarrett Wollman /* 1213ecc48e2SGarrett Wollman * Functions added in C99 which we make conditionally available in the 1223ecc48e2SGarrett Wollman * BSD^C89 namespace if the compiler supports `long long'. 1233ecc48e2SGarrett Wollman * The #if test is more complicated than it ought to be because 1243ecc48e2SGarrett Wollman * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 1253ecc48e2SGarrett Wollman * is not supported in the compilation environment (which therefore means 1263ecc48e2SGarrett Wollman * that it can't really be ISO C99). 1273ecc48e2SGarrett Wollman * 1283ecc48e2SGarrett Wollman * (The only other extension made by C99 in thie header is _Exit().) 1293ecc48e2SGarrett Wollman */ 1303ecc48e2SGarrett Wollman #if __ISO_C_VISIBLE >= 1999 1313ecc48e2SGarrett Wollman #ifdef __LONG_LONG_SUPPORTED 1323ecc48e2SGarrett Wollman /* LONGLONG */ 1333ecc48e2SGarrett Wollman typedef struct { 1343ecc48e2SGarrett Wollman long long quot; 1353ecc48e2SGarrett Wollman long long rem; 1363ecc48e2SGarrett Wollman } lldiv_t; 137798c1fd8SPoul-Henning Kamp 1383ecc48e2SGarrett Wollman /* LONGLONG */ 1393ecc48e2SGarrett Wollman long long 1403ecc48e2SGarrett Wollman atoll(const char *); 1413ecc48e2SGarrett Wollman /* LONGLONG */ 1423ecc48e2SGarrett Wollman long long 1433ecc48e2SGarrett Wollman llabs(long long) __pure2; 1443ecc48e2SGarrett Wollman /* LONGLONG */ 1453ecc48e2SGarrett Wollman lldiv_t lldiv(long long, long long) __pure2; 1463ecc48e2SGarrett Wollman /* LONGLONG */ 1473ecc48e2SGarrett Wollman long long 1483ecc48e2SGarrett Wollman strtoll(const char * __restrict, char ** __restrict, int); 1493ecc48e2SGarrett Wollman /* LONGLONG */ 1503ecc48e2SGarrett Wollman unsigned long long 1513ecc48e2SGarrett Wollman strtoull(const char * __restrict, char ** __restrict, int); 1523ecc48e2SGarrett Wollman #endif /* __LONG_LONG_SUPPORTED */ 1533ecc48e2SGarrett Wollman 1543ecc48e2SGarrett Wollman void _Exit(int) __dead2; 1553ecc48e2SGarrett Wollman #endif /* __ISO_C_VISIBLE >= 1999 */ 1563ecc48e2SGarrett Wollman 1573ecc48e2SGarrett Wollman /* 1583ecc48e2SGarrett Wollman * Extensions made by POSIX relative to C. We don't know yet which edition 1593ecc48e2SGarrett Wollman * of POSIX made these extensions, so assume they've always been there until 1603ecc48e2SGarrett Wollman * research can be done. 1613ecc48e2SGarrett Wollman */ 1623ecc48e2SGarrett Wollman #if __POSIX_VISIBLE /* >= ??? */ 1633ecc48e2SGarrett Wollman /* int posix_memalign(void **, size_t, size_t); (ADV) */ 1643ecc48e2SGarrett Wollman int rand_r(unsigned *); /* (TSF) */ 165bb28f3c2SWarner Losh int setenv(const char *, const char *, int); 1663ecc48e2SGarrett Wollman void unsetenv(const char *); 1673ecc48e2SGarrett Wollman #endif 16859deaec5SRodney W. Grimes 1693ecc48e2SGarrett Wollman /* 1703ecc48e2SGarrett Wollman * The only changes to the XSI namespace in revision 6 were the deletion 1713ecc48e2SGarrett Wollman * of the ttyslot() and valloc() functions, which FreeBSD never declared 1723ecc48e2SGarrett Wollman * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 1733ecc48e2SGarrett Wollman * FreeBSD also does not have, and mktemp(), are to be deleted. 1743ecc48e2SGarrett Wollman */ 1753ecc48e2SGarrett Wollman #if __XSI_VISIBLE 1763ecc48e2SGarrett Wollman /* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 1773ecc48e2SGarrett Wollman /* long a64l(const char *); */ 178bb28f3c2SWarner Losh double drand48(void); 1793ecc48e2SGarrett Wollman /* char *ecvt(double, int, int * __restrict, int * __restrict); */ 180bb28f3c2SWarner Losh double erand48(unsigned short[3]); 1813ecc48e2SGarrett Wollman /* char *fcvt(double, int, int * __restrict, int * __restrict); */ 1823ecc48e2SGarrett Wollman /* char *gcvt(double, int, int * __restrict, int * __restrict); */ 1833ecc48e2SGarrett Wollman #ifndef _GETSUBOPT_DECLARED 1843ecc48e2SGarrett Wollman int getsubopt(char **, char *const *, char **); 1853ecc48e2SGarrett Wollman #define _GETSUBOPT_DECLARED 1863ecc48e2SGarrett Wollman #endif 1873ecc48e2SGarrett Wollman /* int grantpt(int); */ 1883ecc48e2SGarrett Wollman char *initstate(unsigned long /* XSI requires u_int */, char *, long); 189bb28f3c2SWarner Losh long jrand48(unsigned short[3]); 1903ecc48e2SGarrett Wollman /* char *l64a(long); */ 191bb28f3c2SWarner Losh void lcong48(unsigned short[7]); 192bb28f3c2SWarner Losh long lrand48(void); 1933ecc48e2SGarrett Wollman #ifndef _MKSTEMP_DECLARED 1943ecc48e2SGarrett Wollman int mkstemp(char *); 1953ecc48e2SGarrett Wollman #define _MKSTEMP_DECLARED 1963ecc48e2SGarrett Wollman #endif 1973ecc48e2SGarrett Wollman #ifndef _MKTEMP_DECLARED 1983ecc48e2SGarrett Wollman char *mktemp(char *); 1993ecc48e2SGarrett Wollman #define _MKTEMP_DECLARED 2003ecc48e2SGarrett Wollman #endif 201bb28f3c2SWarner Losh long mrand48(void); 202bb28f3c2SWarner Losh long nrand48(unsigned short[3]); 2033ecc48e2SGarrett Wollman /* int posix_openpt(int); */ 2043ecc48e2SGarrett Wollman /* char *ptsname(int); */ 2053ecc48e2SGarrett Wollman int putenv(const char *); 2063ecc48e2SGarrett Wollman long random(void); 2073ecc48e2SGarrett Wollman char *realpath(const char *, char resolved_path[]); 20867c54240SBruce Evans unsigned short 209bb28f3c2SWarner Losh *seed48(unsigned short[3]); 2103ecc48e2SGarrett Wollman #ifndef _SETKEY_DECLARED 2113ecc48e2SGarrett Wollman int setkey(const char *); 2123ecc48e2SGarrett Wollman #define _SETKEY_DECLARED 2133ecc48e2SGarrett Wollman #endif 2143ecc48e2SGarrett Wollman char *setstate(/* const */ char *); 215bb28f3c2SWarner Losh void srand48(long); 2163ecc48e2SGarrett Wollman void srandom(unsigned long); 2173ecc48e2SGarrett Wollman /* int unlockpt(int); */ 2183ecc48e2SGarrett Wollman #endif /* __XSI_VISIBLE */ 2193ecc48e2SGarrett Wollman 2203ecc48e2SGarrett Wollman #if __BSD_VISIBLE 2213ecc48e2SGarrett Wollman extern const char *_malloc_options; 222a4c8a68cSBruce Evans extern void (*_malloc_message)(const char *, const char *, const char *, 223a4c8a68cSBruce Evans const char *); 224f8f6d0dcSAndreas Schulz 225bb28f3c2SWarner Losh void *alloca(size_t); /* built-in for gcc */ 2268252a465SDmitrij Tejblum __uint32_t 227bb28f3c2SWarner Losh arc4random(void); 228bb28f3c2SWarner Losh void arc4random_addrandom(unsigned char *dat, int datlen); 229bb28f3c2SWarner Losh void arc4random_stir(void); 230c2e55537SDavid E. O'Brien char *getbsize(int *, long *); 2313ecc48e2SGarrett Wollman /* getcap(3) functions */ 232bb28f3c2SWarner Losh char *cgetcap(char *, const char *, int); 233bb28f3c2SWarner Losh int cgetclose(void); 234bb28f3c2SWarner Losh int cgetent(char **, char **, const char *); 235bb28f3c2SWarner Losh int cgetfirst(char **, char **); 236bb28f3c2SWarner Losh int cgetmatch(const char *, const char *); 237bb28f3c2SWarner Losh int cgetnext(char **, char **); 238bb28f3c2SWarner Losh int cgetnum(char *, const char *, long *); 239bb28f3c2SWarner Losh int cgetset(const char *); 240bb28f3c2SWarner Losh int cgetstr(char *, const char *, char **); 241bb28f3c2SWarner Losh int cgetustr(char *, const char *, char **); 24259deaec5SRodney W. Grimes 243bb28f3c2SWarner Losh int daemon(int, int); 244bb28f3c2SWarner Losh char *devname(int, int); 245bb28f3c2SWarner Losh int getloadavg(double [], int); 246ec55a605SMike Barcroft __const char * 247bb28f3c2SWarner Losh getprogname(void); 24859deaec5SRodney W. Grimes 249bb28f3c2SWarner Losh int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 250bb28f3c2SWarner Losh int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 2510855f655SGarrett Wollman void qsort_r(void *, size_t, size_t, void *, 2520855f655SGarrett Wollman int (*)(void *, const void *, const void *)); 253bb28f3c2SWarner Losh int radixsort(const unsigned char **, int, const unsigned char *, 254bb28f3c2SWarner Losh unsigned); 255bb28f3c2SWarner Losh void *reallocf(void *, size_t); 256bb28f3c2SWarner Losh void setprogname(const char *); 2570855f655SGarrett Wollman int sradixsort(const unsigned char **, int, const unsigned char *, 2580855f655SGarrett Wollman unsigned); 259bb28f3c2SWarner Losh void sranddev(void); 260bb28f3c2SWarner Losh void srandomdev(void); 2613ecc48e2SGarrett Wollman 2623ecc48e2SGarrett Wollman /* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 263a4c8a68cSBruce Evans __int64_t 264a4c8a68cSBruce Evans strtoq(const char *, char **, int); 2658252a465SDmitrij Tejblum __uint64_t 266bb28f3c2SWarner Losh strtouq(const char *, char **, int); 2673ecc48e2SGarrett Wollman #endif /* __BSD_VISIBLE */ 26859deaec5SRodney W. Grimes __END_DECLS 26959deaec5SRodney W. Grimes 27067c54240SBruce Evans #endif /* !_STDLIB_H_ */ 271