stdlib.h revision 116833
1184610Salfred/*- 2184610Salfred * Copyright (c) 1990, 1993 3184610Salfred * The Regents of the University of California. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 3. All advertising materials mentioning features or use of this software 14184610Salfred * must display the following acknowledgement: 15184610Salfred * This product includes software developed by the University of 16184610Salfred * California, Berkeley and its contributors. 17184610Salfred * 4. Neither the name of the University nor the names of its contributors 18184610Salfred * may be used to endorse or promote products derived from this software 19184610Salfred * without specific prior written permission. 20184610Salfred * 21184610Salfred * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26188417Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29191746Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30191746Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31191746Sthompsa * SUCH DAMAGE. 32191746Sthompsa * 33191746Sthompsa * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 34194677Sthompsa * $FreeBSD: head/include/stdlib.h 116833 2003-06-25 19:06:40Z obrien $ 35191746Sthompsa */ 36191746Sthompsa 37191746Sthompsa#ifndef _STDLIB_H_ 38191746Sthompsa#define _STDLIB_H_ 39191746Sthompsa 40191746Sthompsa#include <sys/cdefs.h> 41191746Sthompsa#include <sys/_types.h> 42191746Sthompsa 43191746Sthompsa#if __BSD_VISIBLE 44191746Sthompsa#ifndef _RUNE_T_DECLARED 45191746Sthompsatypedef __rune_t rune_t; 46191746Sthompsa#define _RUNE_T_DECLARED 47191746Sthompsa#endif 48191746Sthompsa#endif 49191746Sthompsa 50191746Sthompsa#ifndef _SIZE_T_DECLARED 51191746Sthompsatypedef __size_t size_t; 52191746Sthompsa#define _SIZE_T_DECLARED 53191746Sthompsa#endif 54191746Sthompsa 55191746Sthompsa#ifndef __cplusplus 56191746Sthompsa#ifndef _WCHAR_T_DECLARED 57191746Sthompsatypedef __wchar_t wchar_t; 58191746Sthompsa#define _WCHAR_T_DECLARED 59191746Sthompsa#endif 60191746Sthompsa#endif 61191746Sthompsa 62191746Sthompsatypedef struct { 63191746Sthompsa int quot; /* quotient */ 64191746Sthompsa int rem; /* remainder */ 65191746Sthompsa} div_t; 66191746Sthompsa 67191746Sthompsatypedef struct { 68206358Srpaulo long quot; 69191746Sthompsa long rem; 70188942Sthompsa} ldiv_t; 71194677Sthompsa 72194677Sthompsa#ifndef NULL 73191746Sthompsa#define NULL 0 74184610Salfred#endif 75188942Sthompsa 76188942Sthompsa#define EXIT_FAILURE 1 77184610Salfred#define EXIT_SUCCESS 0 78207077Sthompsa 79184610Salfred#define RAND_MAX 0x7fffffff 80184610Salfred 81227309Sedextern int __mb_cur_max; 82192502Sthompsa#define MB_CUR_MAX __mb_cur_max 83184610Salfred 84188417Sthompsa__BEGIN_DECLS 85188417Sthompsavoid abort(void) __dead2; 86188417Sthompsaint abs(int) __pure2; 87188417Sthompsaint atexit(void (*)(void)); 88188417Sthompsadouble atof(const char *); 89188417Sthompsaint atoi(const char *); 90188417Sthompsalong atol(const char *); 91188417Sthompsavoid *bsearch(const void *, const void *, size_t, 92188417Sthompsa size_t, int (*)(const void *, const void *)); 93188417Sthompsavoid *calloc(size_t, size_t); 94188417Sthompsadiv_t div(int, int) __pure2; 95188417Sthompsavoid exit(int) __dead2; 96188417Sthompsavoid free(void *); 97188417Sthompsachar *getenv(const char *); 98188417Sthompsalong labs(long) __pure2; 99188419Sthompsaldiv_t ldiv(long, long) __pure2; 100188417Sthompsavoid *malloc(size_t); 101188417Sthompsaint mblen(const char *, size_t); 102188417Sthompsasize_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 103188417Sthompsaint mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 104188417Sthompsavoid qsort(void *, size_t, size_t, 105188417Sthompsa int (*)(const void *, const void *)); 106184610Salfredint rand(void); 107184610Salfredvoid *realloc(void *, size_t); 108188419Sthompsavoid srand(unsigned); 109194228Sthompsadouble strtod(const char * __restrict, char ** __restrict); 110188419Sthompsafloat strtof(const char * __restrict, char ** __restrict); 111188417Sthompsalong strtol(const char * __restrict, char ** __restrict, int); 112184610Salfredlong double 113184610Salfred strtold(const char * __restrict, char ** __restrict); 114184610Salfredunsigned long 115193045Sthompsa strtoul(const char * __restrict, char ** __restrict, int); 116193045Sthompsaint system(const char *); 117193045Sthompsaint wctomb(char *, wchar_t); 118193045Sthompsasize_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 119184610Salfred 120185948Sthompsa/* 121228621Sbschmidt * Functions added in C99 which we make conditionally available in the 122228621Sbschmidt * BSD^C89 namespace if the compiler supports `long long'. 123228621Sbschmidt * The #if test is more complicated than it ought to be because 124185948Sthompsa * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 125188417Sthompsa * is not supported in the compilation environment (which therefore means 126188419Sthompsa * that it can't really be ISO C99). 127188419Sthompsa * 128188417Sthompsa * (The only other extension made by C99 in thie header is _Exit().) 129188417Sthompsa */ 130188601Sthompsa#if __ISO_C_VISIBLE >= 1999 131188417Sthompsa#ifdef __LONG_LONG_SUPPORTED 132188417Sthompsa/* LONGLONG */ 133188417Sthompsatypedef struct { 134188417Sthompsa long long quot; 135188417Sthompsa long long rem; 136188417Sthompsa} lldiv_t; 137188417Sthompsa 138188417Sthompsa/* LONGLONG */ 139188417Sthompsalong long 140188417Sthompsa atoll(const char *); 141188417Sthompsa/* LONGLONG */ 142188417Sthompsalong long 143188417Sthompsa llabs(long long) __pure2; 144188417Sthompsa/* LONGLONG */ 145188417Sthompsalldiv_t lldiv(long long, long long) __pure2; 146188417Sthompsa/* LONGLONG */ 147188417Sthompsalong long 148188417Sthompsa strtoll(const char * __restrict, char ** __restrict, int); 149188417Sthompsa/* LONGLONG */ 150188417Sthompsaunsigned long long 151188417Sthompsa strtoull(const char * __restrict, char ** __restrict, int); 152188417Sthompsa#endif /* __LONG_LONG_SUPPORTED */ 153192984Sthompsa 154193803Sweongyovoid _Exit(int) __dead2; 155185948Sthompsa#endif /* __ISO_C_VISIBLE >= 1999 */ 156188417Sthompsa 157188417Sthompsa/* 158185948Sthompsa * Extensions made by POSIX relative to C. We don't know yet which edition 159188417Sthompsa * of POSIX made these extensions, so assume they've always been there until 160191746Sthompsa * research can be done. 161188417Sthompsa */ 162191746Sthompsa#if __POSIX_VISIBLE /* >= ??? */ 163188417Sthompsa/* int posix_memalign(void **, size_t, size_t); (ADV) */ 164188417Sthompsaint rand_r(unsigned *); /* (TSF) */ 165188417Sthompsaint setenv(const char *, const char *, int); 166188417Sthompsavoid unsetenv(const char *); 167188417Sthompsa#endif 168188417Sthompsa 169188417Sthompsa/* 170188417Sthompsa * The only changes to the XSI namespace in revision 6 were the deletion 171188417Sthompsa * of the ttyslot() and valloc() functions, which FreeBSD never declared 172188417Sthompsa * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 173188417Sthompsa * FreeBSD also does not have, and mktemp(), are to be deleted. 174188417Sthompsa */ 175188417Sthompsa#if __XSI_VISIBLE 176188417Sthompsa/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 177188417Sthompsa/* long a64l(const char *); */ 178188417Sthompsadouble drand48(void); 179188417Sthompsa/* char *ecvt(double, int, int * __restrict, int * __restrict); */ 180188417Sthompsadouble erand48(unsigned short[3]); 181188417Sthompsa/* char *fcvt(double, int, int * __restrict, int * __restrict); */ 182188417Sthompsa/* char *gcvt(double, int, int * __restrict, int * __restrict); */ 183188417Sthompsa#ifndef _GETSUBOPT_DECLARED 184193420Sweongyoint getsubopt(char **, char *const *, char **); 185193420Sweongyo#define _GETSUBOPT_DECLARED 186193420Sweongyo#endif 187193420Sweongyoint grantpt(int); 188188417Sthompsachar *initstate(unsigned long /* XSI requires u_int */, char *, long); 189188417Sthompsalong jrand48(unsigned short[3]); 190188417Sthompsa/* char *l64a(long); */ 191184610Salfredvoid lcong48(unsigned short[7]); 192184610Salfredlong lrand48(void); 193184610Salfred#ifndef _MKSTEMP_DECLARED 194184610Salfredint mkstemp(char *); 195184610Salfred#define _MKSTEMP_DECLARED 196188417Sthompsa#endif 197188417Sthompsa#ifndef _MKTEMP_DECLARED 198184610Salfredchar *mktemp(char *); 199193419Sweongyo#define _MKTEMP_DECLARED 200193419Sweongyo#endif 201193419Sweongyolong mrand48(void); 202193419Sweongyolong nrand48(unsigned short[3]); 203223486Shselaskyint posix_openpt(int); 204193419Sweongyochar *ptsname(int); 205193419Sweongyoint putenv(const char *); 206193419Sweongyolong random(void); 207193419Sweongyochar *realpath(const char *, char resolved_path[]); 208193419Sweongyounsigned short 209193419Sweongyo *seed48(unsigned short[3]); 210193419Sweongyo#ifndef _SETKEY_DECLARED 211193419Sweongyoint setkey(const char *); 212193419Sweongyo#define _SETKEY_DECLARED 213193419Sweongyo#endif 214193419Sweongyochar *setstate(/* const */ char *); 215193419Sweongyovoid srand48(long); 216193419Sweongyovoid srandom(unsigned long); 217193419Sweongyoint unlockpt(int); 218193419Sweongyo#endif /* __XSI_VISIBLE */ 219193419Sweongyo 220193419Sweongyo#if __BSD_VISIBLE 221193419Sweongyoextern const char *_malloc_options; 222193419Sweongyoextern void (*_malloc_message)(const char *, const char *, const char *, 223193419Sweongyo const char *); 224193419Sweongyo 225193419Sweongyo/* 226193419Sweongyo * The alloca() function can't be implemented in C, and on some 227193419Sweongyo * platforms it can't be implemented at all as a callable function. 228193419Sweongyo * The GNU C compiler provides a built-in alloca() which we can use; 229193419Sweongyo * in all other cases, provide a prototype, mainly to pacify various 230193419Sweongyo * incarnations of lint. On platforms where alloca() is not in libc, 231193419Sweongyo * programs which use it will fail to link when compiled with non-GNU 232223566Sgavin * compilers. 233193419Sweongyo */ 234193419Sweongyo#if __GNUC__ >= 2 || defined(__INTEL_COMPILER) 235193419Sweongyo#undef alloca /* some GNU bits try to get cute and define this on their own */ 236193419Sweongyo#define alloca(sz) __builtin_alloca(sz) 237193419Sweongyo#elif defined(lint) 238193419Sweongyovoid *alloca(size_t); 239193419Sweongyo#endif 240193419Sweongyo 241193419Sweongyo__uint32_t 242193419Sweongyo arc4random(void); 243193419Sweongyovoid arc4random_addrandom(unsigned char *dat, int datlen); 244193419Sweongyovoid arc4random_stir(void); 245193419Sweongyochar *getbsize(int *, long *); 246193419Sweongyo /* getcap(3) functions */ 247193419Sweongyochar *cgetcap(char *, const char *, int); 248193419Sweongyoint cgetclose(void); 249193419Sweongyoint cgetent(char **, char **, const char *); 250193419Sweongyoint cgetfirst(char **, char **); 251193419Sweongyoint cgetmatch(const char *, const char *); 252193419Sweongyoint cgetnext(char **, char **); 253184610Salfredint cgetnum(char *, const char *, long *); 254184610Salfredint cgetset(const char *); 255192984Sthompsaint cgetstr(char *, const char *, char **); 256188417Sthompsaint cgetustr(char *, const char *, char **); 257184610Salfred 258184610Salfredint daemon(int, int); 259184610Salfredchar *devname(int, int); 260190734Sthompsachar *devname_r(int, int, char *, int); 261190734Sthompsaint getloadavg(double [], int); 262190734Sthompsa__const char * 263184610Salfred getprogname(void); 264190734Sthompsa 265184610Salfredint heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 266188417Sthompsaint mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 267184610Salfredvoid qsort_r(void *, size_t, size_t, void *, 268184610Salfred int (*)(void *, const void *, const void *)); 269184610Salfredint radixsort(const unsigned char **, int, const unsigned char *, 270190734Sthompsa unsigned); 271190734Sthompsavoid *reallocf(void *, size_t); 272190734Sthompsavoid setprogname(const char *); 273184610Salfredint sradixsort(const unsigned char **, int, const unsigned char *, 274184610Salfred unsigned); 275188417Sthompsavoid sranddev(void); 276184610Salfredvoid srandomdev(void); 277184610Salfred 278184610Salfred/* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 279190734Sthompsa__int64_t 280190734Sthompsa strtoq(const char *, char **, int); 281190734Sthompsa__uint64_t 282190734Sthompsa strtouq(const char *, char **, int); 283184610Salfred#endif /* __BSD_VISIBLE */ 284184610Salfred__END_DECLS 285188417Sthompsa 286188417Sthompsa#endif /* !_STDLIB_H_ */ 287184610Salfred