stdlib.h revision 116397
11590Srgrimes/*- 21590Srgrimes * Copyright (c) 1990, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 3. All advertising materials mentioning features or use of this software 141590Srgrimes * must display the following acknowledgement: 151590Srgrimes * This product includes software developed by the University of 161590Srgrimes * California, Berkeley and its contributors. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2950477Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31264332Sbdrewery * SUCH DAMAGE. 321590Srgrimes * 3379535Sru * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 341590Srgrimes * $FreeBSD: head/include/stdlib.h 116397 2003-06-15 11:01:52Z des $ 351590Srgrimes */ 361590Srgrimes 371590Srgrimes#ifndef _STDLIB_H_ 3825189Sjmg#define _STDLIB_H_ 39264332Sbdrewery 40123306Speter#include <sys/cdefs.h> 411590Srgrimes#include <sys/_types.h> 42115759Speter 43177856Sru#if __BSD_VISIBLE 441590Srgrimes#ifndef _RUNE_T_DECLARED 4525189Sjmgtypedef __rune_t rune_t; 4625189Sjmg#define _RUNE_T_DECLARED 4725189Sjmg#endif 481590Srgrimes#endif 491590Srgrimes 501590Srgrimes#ifndef _SIZE_T_DECLARED 511590Srgrimestypedef __size_t size_t; 521590Srgrimes#define _SIZE_T_DECLARED 531590Srgrimes#endif 541590Srgrimes 551590Srgrimes#ifndef __cplusplus 561590Srgrimes#ifndef _WCHAR_T_DECLARED 571590Srgrimestypedef __wchar_t wchar_t; 58123306Speter#define _WCHAR_T_DECLARED 59123306Speter#endif 60123306Speter#endif 611590Srgrimes 621590Srgrimestypedef struct { 63151930Srwatson int quot; /* quotient */ 64152568Sru int rem; /* remainder */ 65152568Sru} div_t; 661590Srgrimes 671590Srgrimestypedef struct { 681590Srgrimes long quot; 6979755Sdd long rem; 701590Srgrimes} ldiv_t; 711590Srgrimes 721590Srgrimes#ifndef NULL 731590Srgrimes#define NULL 0 741590Srgrimes#endif 751590Srgrimes 761590Srgrimes#define EXIT_FAILURE 1 7725189Sjmg#define EXIT_SUCCESS 0 781590Srgrimes 791590Srgrimes#define RAND_MAX 0x7fffffff 801590Srgrimes 811590Srgrimesextern int __mb_cur_max; 821590Srgrimes#define MB_CUR_MAX __mb_cur_max 831590Srgrimes 841590Srgrimes__BEGIN_DECLS 851590Srgrimesvoid abort(void) __dead2; 861590Srgrimesint abs(int) __pure2; 871590Srgrimesint atexit(void (*)(void)); 88115759Speterdouble atof(const char *); 89236577Sjhbint atoi(const char *); 90115759Speterlong atol(const char *); 91236577Sjhbvoid *bsearch(const void *, const void *, size_t, 92115759Speter size_t, int (*)(const void *, const void *)); 931590Srgrimesvoid *calloc(size_t, size_t); 941590Srgrimesdiv_t div(int, int) __pure2; 95176471Sdesvoid exit(int) __dead2; 96176471Sdesvoid free(void *); 97176471Sdeschar *getenv(const char *); 98264332Sbdrewerylong labs(long) __pure2; 99264332Sbdreweryldiv_t ldiv(long, long) __pure2; 100152331Srwatsonvoid *malloc(size_t); 101152331Srwatsonint mblen(const char *, size_t); 1021590Srgrimessize_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 1031590Srgrimesint mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 104219044Sdchaginvoid qsort(void *, size_t, size_t, 105219044Sdchagin int (*)(const void *, const void *)); 106177856Sruint rand(void); 1071590Srgrimesvoid *realloc(void *, size_t); 1081590Srgrimesvoid srand(unsigned); 1091590Srgrimesdouble strtod(const char * __restrict, char ** __restrict); 1101590Srgrimesfloat strtof(const char * __restrict, char ** __restrict); 1111590Srgrimeslong strtol(const char * __restrict, char ** __restrict, int); 112140933Sgnnlong double 113140933Sgnn strtold(const char * __restrict, char ** __restrict); 114140933Sgnnunsigned long 115140933Sgnn strtoul(const char * __restrict, char ** __restrict, int); 116140933Sgnnint system(const char *); 117140933Sgnnint wctomb(char *, wchar_t); 118140933Sgnnsize_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 119140933Sgnn 120140933Sgnn/* 121140933Sgnn * Functions added in C99 which we make conditionally available in the 122140933Sgnn * BSD^C89 namespace if the compiler supports `long long'. 123140933Sgnn * The #if test is more complicated than it ought to be because 124140933Sgnn * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 125140933Sgnn * is not supported in the compilation environment (which therefore means 126140933Sgnn * that it can't really be ISO C99). 127140933Sgnn * 128140933Sgnn * (The only other extension made by C99 in thie header is _Exit().) 129140933Sgnn */ 130140933Sgnn#if __ISO_C_VISIBLE >= 1999 131140933Sgnn#ifdef __LONG_LONG_SUPPORTED 132140933Sgnn/* LONGLONG */ 133140933Sgnntypedef struct { 134151930Srwatson long long quot; 135152568Sru long long rem; 136140933Sgnn} lldiv_t; 137140933Sgnn 138140933Sgnn/* LONGLONG */ 139140933Sgnnlong long 140140933Sgnn atoll(const char *); 141140933Sgnn/* LONGLONG */ 142140933Sgnnlong long 143140933Sgnn llabs(long long) __pure2; 144140933Sgnn/* LONGLONG */ 145140933Sgnnlldiv_t lldiv(long long, long long) __pure2; 146140933Sgnn/* LONGLONG */ 147140933Sgnnlong long 148140933Sgnn strtoll(const char * __restrict, char ** __restrict, int); 149140933Sgnn/* LONGLONG */ 150140933Sgnnunsigned long long 151140933Sgnn strtoull(const char * __restrict, char ** __restrict, int); 152140933Sgnn#endif /* __LONG_LONG_SUPPORTED */ 153140933Sgnn 154140933Sgnnvoid _Exit(int) __dead2; 155140933Sgnn#endif /* __ISO_C_VISIBLE >= 1999 */ 156140933Sgnn 157140933Sgnn/* 158140933Sgnn * Extensions made by POSIX relative to C. We don't know yet which edition 159140933Sgnn * of POSIX made these extensions, so assume they've always been there until 160140933Sgnn * research can be done. 161140933Sgnn */ 162140933Sgnn#if __POSIX_VISIBLE /* >= ??? */ 163140933Sgnn/* int posix_memalign(void **, size_t, size_t); (ADV) */ 164140933Sgnnint rand_r(unsigned *); /* (TSF) */ 165214625Sjhbint setenv(const char *, const char *, int); 166140933Sgnnvoid unsetenv(const char *); 167140933Sgnn#endif 168140933Sgnn 169140933Sgnn/* 170214625Sjhb * The only changes to the XSI namespace in revision 6 were the deletion 171214625Sjhb * of the ttyslot() and valloc() functions, which FreeBSD never declared 172234494Sjhb * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 173140933Sgnn * FreeBSD also does not have, and mktemp(), are to be deleted. 174176471Sdes */ 175189707Sjhb#if __XSI_VISIBLE 176233925Sjhb/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 177233925Sjhb/* long a64l(const char *); */ 178140933Sgnndouble drand48(void); 1791590Srgrimes/* char *ecvt(double, int, int * __restrict, int * __restrict); */ 1801590Srgrimesdouble erand48(unsigned short[3]); 1811590Srgrimes/* char *fcvt(double, int, int * __restrict, int * __restrict); */ 1821590Srgrimes/* char *gcvt(double, int, int * __restrict, int * __restrict); */ 18325189Sjmg#ifndef _GETSUBOPT_DECLARED 18425189Sjmgint getsubopt(char **, char *const *, char **); 1851590Srgrimes#define _GETSUBOPT_DECLARED 186#endif 187int grantpt(int); 188char *initstate(unsigned long /* XSI requires u_int */, char *, long); 189long jrand48(unsigned short[3]); 190/* char *l64a(long); */ 191void lcong48(unsigned short[7]); 192long lrand48(void); 193#ifndef _MKSTEMP_DECLARED 194int mkstemp(char *); 195#define _MKSTEMP_DECLARED 196#endif 197#ifndef _MKTEMP_DECLARED 198char *mktemp(char *); 199#define _MKTEMP_DECLARED 200#endif 201long mrand48(void); 202long nrand48(unsigned short[3]); 203int posix_openpt(int); 204char *ptsname(int); 205int putenv(const char *); 206long random(void); 207char *realpath(const char *, char resolved_path[]); 208unsigned short 209 *seed48(unsigned short[3]); 210#ifndef _SETKEY_DECLARED 211int setkey(const char *); 212#define _SETKEY_DECLARED 213#endif 214char *setstate(/* const */ char *); 215void srand48(long); 216void srandom(unsigned long); 217int unlockpt(int); 218#endif /* __XSI_VISIBLE */ 219 220#if __BSD_VISIBLE 221extern const char *_malloc_options; 222extern void (*_malloc_message)(const char *, const char *, const char *, 223 const char *); 224 225#ifndef alloca 226/* 227 * The alloca() function can't be implemented in C, and on some 228 * platforms it can't be implemented at all as a callable function. 229 * The GNU C compiler provides a built-in alloca() which we can use; 230 * in all other cases, provide a prototype, mainly to pacify various 231 * incarnations of lint. On platforms where alloca() is not in libc, 232 * programs which use it will fail to link when compiled with non-GNU 233 * compilers. 234 */ 235#if defined(__GNUC__) || defined(__INTEL_COMPILER) 236#define alloca(sz) __builtin_alloca(sz) 237#else 238void *alloca(size_t); 239#endif 240#endif 241 242__uint32_t 243 arc4random(void); 244void arc4random_addrandom(unsigned char *dat, int datlen); 245void arc4random_stir(void); 246char *getbsize(int *, long *); 247 /* getcap(3) functions */ 248char *cgetcap(char *, const char *, int); 249int cgetclose(void); 250int cgetent(char **, char **, const char *); 251int cgetfirst(char **, char **); 252int cgetmatch(const char *, const char *); 253int cgetnext(char **, char **); 254int cgetnum(char *, const char *, long *); 255int cgetset(const char *); 256int cgetstr(char *, const char *, char **); 257int cgetustr(char *, const char *, char **); 258 259int daemon(int, int); 260char *devname(int, int); 261int getloadavg(double [], int); 262__const char * 263 getprogname(void); 264 265int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 266int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 267void qsort_r(void *, size_t, size_t, void *, 268 int (*)(void *, const void *, const void *)); 269int radixsort(const unsigned char **, int, const unsigned char *, 270 unsigned); 271void *reallocf(void *, size_t); 272void setprogname(const char *); 273int sradixsort(const unsigned char **, int, const unsigned char *, 274 unsigned); 275void sranddev(void); 276void srandomdev(void); 277 278/* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 279__int64_t 280 strtoq(const char *, char **, int); 281__uint64_t 282 strtouq(const char *, char **, int); 283#endif /* __BSD_VISIBLE */ 284__END_DECLS 285 286#endif /* !_STDLIB_H_ */ 287