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 43cdd84b02SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 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 { 6859deaec5SRodney W. Grimes long quot; /* quotient */ 6959deaec5SRodney W. Grimes long rem; /* remainder */ 7059deaec5SRodney W. Grimes } ldiv_t; 7159deaec5SRodney W. Grimes 72614b3667SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 737a4a6327SMike Barcroft #ifdef __LONG_LONG_SUPPORTED 74108b116dSMark Murray /* LONGLONG */ 757a4a6327SMike Barcroft typedef struct { 767a4a6327SMike Barcroft long long quot; 777a4a6327SMike Barcroft long long rem; 787a4a6327SMike Barcroft } lldiv_t; 797a4a6327SMike Barcroft #endif 80614b3667SBruce Evans #endif 817a4a6327SMike Barcroft 8259deaec5SRodney W. Grimes #ifndef NULL 8359deaec5SRodney W. Grimes #define NULL 0 8459deaec5SRodney W. Grimes #endif 8559deaec5SRodney W. Grimes 8659deaec5SRodney W. Grimes #define EXIT_FAILURE 1 8759deaec5SRodney W. Grimes #define EXIT_SUCCESS 0 8859deaec5SRodney W. Grimes 8959deaec5SRodney W. Grimes #define RAND_MAX 0x7fffffff 9059deaec5SRodney W. Grimes 9159deaec5SRodney W. Grimes extern int __mb_cur_max; 9259deaec5SRodney W. Grimes #define MB_CUR_MAX __mb_cur_max 9359deaec5SRodney W. Grimes 9459deaec5SRodney W. Grimes __BEGIN_DECLS 95bb28f3c2SWarner Losh void abort(void) __dead2; 96bb28f3c2SWarner Losh int abs(int) __pure2; 97bb28f3c2SWarner Losh int atexit(void (*)(void)); 98bb28f3c2SWarner Losh double atof(const char *); 99bb28f3c2SWarner Losh int atoi(const char *); 100bb28f3c2SWarner Losh long atol(const char *); 101bb28f3c2SWarner Losh void *bsearch(const void *, const void *, size_t, 102bb28f3c2SWarner Losh size_t, int (*)(const void *, const void *)); 103bb28f3c2SWarner Losh void *calloc(size_t, size_t); 104bb28f3c2SWarner Losh div_t div(int, int) __pure2; 105bb28f3c2SWarner Losh void exit(int) __dead2; 106bb28f3c2SWarner Losh void free(void *); 107bb28f3c2SWarner Losh char *getenv(const char *); 108bb28f3c2SWarner Losh long labs(long) __pure2; 109bb28f3c2SWarner Losh ldiv_t ldiv(long, long) __pure2; 110bb28f3c2SWarner Losh void *malloc(size_t); 111bb28f3c2SWarner Losh void qsort(void *, size_t, size_t, 112bb28f3c2SWarner Losh int (*)(const void *, const void *)); 113bb28f3c2SWarner Losh int rand(void); 114bb28f3c2SWarner Losh void *realloc(void *, size_t); 115bb28f3c2SWarner Losh void srand(unsigned); 1165618f724SRobert Drehmel double strtod(const char *__restrict, char **__restrict); 1175618f724SRobert Drehmel long strtol(const char *__restrict, char **__restrict, int); 11859deaec5SRodney W. Grimes unsigned long 1195618f724SRobert Drehmel strtoul(const char *__restrict, char **__restrict, int); 120bb28f3c2SWarner Losh int system(const char *); 12159deaec5SRodney W. Grimes 122bb28f3c2SWarner Losh int mblen(const char *, size_t); 123bb28f3c2SWarner Losh size_t mbstowcs(wchar_t *, const char *, size_t); 124bb28f3c2SWarner Losh int wctomb(char *, wchar_t); 125bb28f3c2SWarner Losh int mbtowc(wchar_t *, const char *, size_t); 126bb28f3c2SWarner Losh size_t wcstombs(char *, const wchar_t *, size_t); 12759deaec5SRodney W. Grimes 12867c54240SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 1299908ed2bSPoul-Henning Kamp extern const char *_malloc_options; 130ff84d98aSPoul-Henning Kamp extern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4); 131798c1fd8SPoul-Henning Kamp 132bb28f3c2SWarner Losh int putenv(const char *); 133bb28f3c2SWarner Losh int setenv(const char *, const char *, int); 13459deaec5SRodney W. Grimes 135bb28f3c2SWarner Losh double drand48(void); 136bb28f3c2SWarner Losh double erand48(unsigned short[3]); 137bb28f3c2SWarner Losh long jrand48(unsigned short[3]); 138bb28f3c2SWarner Losh void lcong48(unsigned short[7]); 139bb28f3c2SWarner Losh long lrand48(void); 140bb28f3c2SWarner Losh long mrand48(void); 141bb28f3c2SWarner Losh long nrand48(unsigned short[3]); 14267c54240SBruce Evans unsigned short 143bb28f3c2SWarner Losh *seed48(unsigned short[3]); 144bb28f3c2SWarner Losh void srand48(long); 145f8f6d0dcSAndreas Schulz 146bb28f3c2SWarner Losh void *alloca(size_t); /* built-in for gcc */ 14759deaec5SRodney W. Grimes /* getcap(3) functions */ 1488252a465SDmitrij Tejblum __uint32_t 149bb28f3c2SWarner Losh arc4random(void); 150bb28f3c2SWarner Losh void arc4random_addrandom(unsigned char *dat, int datlen); 151bb28f3c2SWarner Losh void arc4random_stir(void); 152930dbabbSBruce Evans #ifdef __LONG_LONG_SUPPORTED 153108b116dSMark Murray /* LONGLONG */ 154930dbabbSBruce Evans long long 155bb28f3c2SWarner Losh atoll(const char *); 156930dbabbSBruce Evans #endif 157bb28f3c2SWarner Losh char *getbsize(int *, long *); 158bb28f3c2SWarner Losh char *cgetcap(char *, const char *, int); 159bb28f3c2SWarner Losh int cgetclose(void); 160bb28f3c2SWarner Losh int cgetent(char **, char **, const char *); 161bb28f3c2SWarner Losh int cgetfirst(char **, char **); 162bb28f3c2SWarner Losh int cgetmatch(const char *, const char *); 163bb28f3c2SWarner Losh int cgetnext(char **, char **); 164bb28f3c2SWarner Losh int cgetnum(char *, const char *, long *); 165bb28f3c2SWarner Losh int cgetset(const char *); 166bb28f3c2SWarner Losh int cgetstr(char *, const char *, char **); 167bb28f3c2SWarner Losh int cgetustr(char *, const char *, char **); 16859deaec5SRodney W. Grimes 169bb28f3c2SWarner Losh int daemon(int, int); 170bb28f3c2SWarner Losh char *devname(int, int); 171bb28f3c2SWarner Losh int getloadavg(double [], int); 172ec55a605SMike Barcroft __const char * 173bb28f3c2SWarner Losh getprogname(void); 17459deaec5SRodney W. Grimes 175bb28f3c2SWarner Losh int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 176bb28f3c2SWarner Losh char *initstate(unsigned long, char *, long); 177614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 178108b116dSMark Murray /* LONGLONG */ 179614b3667SBruce Evans long long 180bb28f3c2SWarner Losh llabs(long long) __pure2; 181bb28f3c2SWarner Losh lldiv_t lldiv(long long, long long) __pure2; 182614b3667SBruce Evans #endif 183bb28f3c2SWarner Losh int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 184bb28f3c2SWarner Losh int radixsort(const unsigned char **, int, const unsigned char *, 185bb28f3c2SWarner Losh unsigned); 186bb28f3c2SWarner Losh int sradixsort(const unsigned char **, int, const unsigned char *, 187bb28f3c2SWarner Losh unsigned); 188bb28f3c2SWarner Losh int rand_r(unsigned *); 189bb28f3c2SWarner Losh long random(void); 190bb28f3c2SWarner Losh void *reallocf(void *, size_t); 191bb28f3c2SWarner Losh char *realpath(const char *, char resolved_path[]); 192bb28f3c2SWarner Losh void setprogname(const char *); 193bb28f3c2SWarner Losh char *setstate(char *); 194bb28f3c2SWarner Losh void sranddev(void); 195bb28f3c2SWarner Losh void srandom(unsigned long); 196bb28f3c2SWarner Losh void srandomdev(void); 197614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 198108b116dSMark Murray /* LONGLONG */ 199614b3667SBruce Evans long long 2005618f724SRobert Drehmel strtoll(const char *__restrict, char **__restrict, int); 201614b3667SBruce Evans #endif 202bb28f3c2SWarner Losh __int64_t strtoq(const char *, char **, int); 203614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 204108b116dSMark Murray /* LONGLONG */ 205614b3667SBruce Evans unsigned long long 2065618f724SRobert Drehmel strtoull(const char *__restrict, char **__restrict, int); 207614b3667SBruce Evans #endif 2088252a465SDmitrij Tejblum __uint64_t 209bb28f3c2SWarner Losh strtouq(const char *, char **, int); 210bb28f3c2SWarner Losh void unsetenv(const char *); 21167c54240SBruce Evans #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 21259deaec5SRodney W. Grimes __END_DECLS 21359deaec5SRodney W. Grimes 21467c54240SBruce Evans #endif /* !_STDLIB_H_ */ 215