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> 4185b46962SBruce Evans 4259deaec5SRodney W. Grimes #include <machine/ansi.h> 4359deaec5SRodney W. Grimes 44cdd84b02SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 45cdd84b02SBruce Evans #ifdef _BSD_RUNE_T_ 46cdd84b02SBruce Evans typedef _BSD_RUNE_T_ rune_t; 47cdd84b02SBruce Evans #undef _BSD_RUNE_T_ 48cdd84b02SBruce Evans #endif 49cdd84b02SBruce Evans #endif 50cdd84b02SBruce Evans 5159deaec5SRodney W. Grimes #ifdef _BSD_SIZE_T_ 5259deaec5SRodney W. Grimes typedef _BSD_SIZE_T_ size_t; 5359deaec5SRodney W. Grimes #undef _BSD_SIZE_T_ 5459deaec5SRodney W. Grimes #endif 5559deaec5SRodney W. Grimes 566087d244SDavid E. O'Brien #ifndef __cplusplus 5759deaec5SRodney W. Grimes #ifdef _BSD_WCHAR_T_ 5859deaec5SRodney W. Grimes typedef _BSD_WCHAR_T_ wchar_t; 5959deaec5SRodney W. Grimes #undef _BSD_WCHAR_T_ 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 { 6959deaec5SRodney W. Grimes long quot; /* quotient */ 7059deaec5SRodney W. Grimes long rem; /* remainder */ 7159deaec5SRodney W. Grimes } ldiv_t; 7259deaec5SRodney W. Grimes 73614b3667SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 747a4a6327SMike Barcroft #ifdef __LONG_LONG_SUPPORTED 75108b116dSMark Murray /* LONGLONG */ 767a4a6327SMike Barcroft typedef struct { 777a4a6327SMike Barcroft long long quot; 787a4a6327SMike Barcroft long long rem; 797a4a6327SMike Barcroft } lldiv_t; 807a4a6327SMike Barcroft #endif 81614b3667SBruce Evans #endif 827a4a6327SMike Barcroft 8359deaec5SRodney W. Grimes #ifndef NULL 8459deaec5SRodney W. Grimes #define NULL 0 8559deaec5SRodney W. Grimes #endif 8659deaec5SRodney W. Grimes 8759deaec5SRodney W. Grimes #define EXIT_FAILURE 1 8859deaec5SRodney W. Grimes #define EXIT_SUCCESS 0 8959deaec5SRodney W. Grimes 9059deaec5SRodney W. Grimes #define RAND_MAX 0x7fffffff 9159deaec5SRodney W. Grimes 9259deaec5SRodney W. Grimes extern int __mb_cur_max; 9359deaec5SRodney W. Grimes #define MB_CUR_MAX __mb_cur_max 9459deaec5SRodney W. Grimes 9559deaec5SRodney W. Grimes __BEGIN_DECLS 96bb28f3c2SWarner Losh void abort(void) __dead2; 97bb28f3c2SWarner Losh int abs(int) __pure2; 98bb28f3c2SWarner Losh int atexit(void (*)(void)); 99bb28f3c2SWarner Losh double atof(const char *); 100bb28f3c2SWarner Losh int atoi(const char *); 101bb28f3c2SWarner Losh long atol(const char *); 102bb28f3c2SWarner Losh void *bsearch(const void *, const void *, size_t, 103bb28f3c2SWarner Losh size_t, int (*)(const void *, const void *)); 104bb28f3c2SWarner Losh void *calloc(size_t, size_t); 105bb28f3c2SWarner Losh div_t div(int, int) __pure2; 106bb28f3c2SWarner Losh void exit(int) __dead2; 107bb28f3c2SWarner Losh void free(void *); 108bb28f3c2SWarner Losh char *getenv(const char *); 109bb28f3c2SWarner Losh long labs(long) __pure2; 110bb28f3c2SWarner Losh ldiv_t ldiv(long, long) __pure2; 111bb28f3c2SWarner Losh void *malloc(size_t); 112bb28f3c2SWarner Losh void qsort(void *, size_t, size_t, 113bb28f3c2SWarner Losh int (*)(const void *, const void *)); 114bb28f3c2SWarner Losh int rand(void); 115bb28f3c2SWarner Losh void *realloc(void *, size_t); 116bb28f3c2SWarner Losh void srand(unsigned); 117bb28f3c2SWarner Losh double strtod(const char *, char **); 118bb28f3c2SWarner Losh long strtol(const char *, char **, int); 11959deaec5SRodney W. Grimes unsigned long 120bb28f3c2SWarner Losh strtoul(const char *, char **, int); 121bb28f3c2SWarner Losh int system(const char *); 12259deaec5SRodney W. Grimes 123bb28f3c2SWarner Losh int mblen(const char *, size_t); 124bb28f3c2SWarner Losh size_t mbstowcs(wchar_t *, const char *, size_t); 125bb28f3c2SWarner Losh int wctomb(char *, wchar_t); 126bb28f3c2SWarner Losh int mbtowc(wchar_t *, const char *, size_t); 127bb28f3c2SWarner Losh size_t wcstombs(char *, const wchar_t *, size_t); 12859deaec5SRodney W. Grimes 12967c54240SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 1309908ed2bSPoul-Henning Kamp extern const char *_malloc_options; 131ff84d98aSPoul-Henning Kamp extern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4); 132798c1fd8SPoul-Henning Kamp 133bb28f3c2SWarner Losh int putenv(const char *); 134bb28f3c2SWarner Losh int setenv(const char *, const char *, int); 13559deaec5SRodney W. Grimes 136bb28f3c2SWarner Losh double drand48(void); 137bb28f3c2SWarner Losh double erand48(unsigned short[3]); 138bb28f3c2SWarner Losh long jrand48(unsigned short[3]); 139bb28f3c2SWarner Losh void lcong48(unsigned short[7]); 140bb28f3c2SWarner Losh long lrand48(void); 141bb28f3c2SWarner Losh long mrand48(void); 142bb28f3c2SWarner Losh long nrand48(unsigned short[3]); 14367c54240SBruce Evans unsigned short 144bb28f3c2SWarner Losh *seed48(unsigned short[3]); 145bb28f3c2SWarner Losh void srand48(long); 146f8f6d0dcSAndreas Schulz 147bb28f3c2SWarner Losh void *alloca(size_t); /* built-in for gcc */ 14859deaec5SRodney W. Grimes /* getcap(3) functions */ 1498252a465SDmitrij Tejblum __uint32_t 150bb28f3c2SWarner Losh arc4random(void); 151bb28f3c2SWarner Losh void arc4random_addrandom(unsigned char *dat, int datlen); 152bb28f3c2SWarner Losh void arc4random_stir(void); 153930dbabbSBruce Evans #ifdef __LONG_LONG_SUPPORTED 154108b116dSMark Murray /* LONGLONG */ 155930dbabbSBruce Evans long long 156bb28f3c2SWarner Losh atoll(const char *); 157930dbabbSBruce Evans #endif 158bb28f3c2SWarner Losh char *getbsize(int *, long *); 159bb28f3c2SWarner Losh char *cgetcap(char *, const char *, int); 160bb28f3c2SWarner Losh int cgetclose(void); 161bb28f3c2SWarner Losh int cgetent(char **, char **, const char *); 162bb28f3c2SWarner Losh int cgetfirst(char **, char **); 163bb28f3c2SWarner Losh int cgetmatch(const char *, const char *); 164bb28f3c2SWarner Losh int cgetnext(char **, char **); 165bb28f3c2SWarner Losh int cgetnum(char *, const char *, long *); 166bb28f3c2SWarner Losh int cgetset(const char *); 167bb28f3c2SWarner Losh int cgetstr(char *, const char *, char **); 168bb28f3c2SWarner Losh int cgetustr(char *, const char *, char **); 16959deaec5SRodney W. Grimes 170bb28f3c2SWarner Losh int daemon(int, int); 171bb28f3c2SWarner Losh char *devname(int, int); 172bb28f3c2SWarner Losh int getloadavg(double [], int); 173ec55a605SMike Barcroft __const char * 174bb28f3c2SWarner Losh getprogname(void); 17559deaec5SRodney W. Grimes 176bb28f3c2SWarner Losh int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 177bb28f3c2SWarner Losh char *initstate(unsigned long, char *, long); 178614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 179108b116dSMark Murray /* LONGLONG */ 180614b3667SBruce Evans long long 181bb28f3c2SWarner Losh llabs(long long) __pure2; 182bb28f3c2SWarner Losh lldiv_t lldiv(long long, long long) __pure2; 183614b3667SBruce Evans #endif 184bb28f3c2SWarner Losh int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 185bb28f3c2SWarner Losh int radixsort(const unsigned char **, int, const unsigned char *, 186bb28f3c2SWarner Losh unsigned); 187bb28f3c2SWarner Losh int sradixsort(const unsigned char **, int, const unsigned char *, 188bb28f3c2SWarner Losh unsigned); 189bb28f3c2SWarner Losh int rand_r(unsigned *); 190bb28f3c2SWarner Losh long random(void); 191bb28f3c2SWarner Losh void *reallocf(void *, size_t); 192bb28f3c2SWarner Losh char *realpath(const char *, char resolved_path[]); 193bb28f3c2SWarner Losh void setprogname(const char *); 194bb28f3c2SWarner Losh char *setstate(char *); 195bb28f3c2SWarner Losh void sranddev(void); 196bb28f3c2SWarner Losh void srandom(unsigned long); 197bb28f3c2SWarner Losh void srandomdev(void); 198614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 199108b116dSMark Murray /* LONGLONG */ 200614b3667SBruce Evans long long 201bb28f3c2SWarner Losh strtoll(const char *, char **, int); 202614b3667SBruce Evans #endif 203bb28f3c2SWarner Losh __int64_t strtoq(const char *, char **, int); 204614b3667SBruce Evans #ifdef __LONG_LONG_SUPPORTED 205108b116dSMark Murray /* LONGLONG */ 206614b3667SBruce Evans unsigned long long 207bb28f3c2SWarner Losh strtoull(const char *, char **, int); 208614b3667SBruce Evans #endif 2098252a465SDmitrij Tejblum __uint64_t 210bb28f3c2SWarner Losh strtouq(const char *, char **, int); 211bb28f3c2SWarner Losh void unsetenv(const char *); 21267c54240SBruce Evans #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 21359deaec5SRodney W. Grimes __END_DECLS 21459deaec5SRodney W. Grimes 21567c54240SBruce Evans #endif /* !_STDLIB_H_ */ 216