stdlib.h revision 187961
11539Srgrimes/*- 21539Srgrimes * Copyright (c) 1990, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 91539Srgrimes * notice, this list of conditions and the following disclaimer. 101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 121539Srgrimes * documentation and/or other materials provided with the distribution. 131539Srgrimes * 3. All advertising materials mentioning features or use of this software 141539Srgrimes * must display the following acknowledgement: 151539Srgrimes * This product includes software developed by the University of 161539Srgrimes * California, Berkeley and its contributors. 171539Srgrimes * 4. Neither the name of the University nor the names of its contributors 181539Srgrimes * may be used to endorse or promote products derived from this software 191539Srgrimes * without specific prior written permission. 201539Srgrimes * 211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311539Srgrimes * SUCH DAMAGE. 321539Srgrimes * 3323657Speter * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 3455031Sbde * $FreeBSD: head/include/stdlib.h 187961 2009-01-31 18:27:02Z das $ 351539Srgrimes */ 361539Srgrimes 371539Srgrimes#ifndef _STDLIB_H_ 387865Sbde#define _STDLIB_H_ 391539Srgrimes 4033861Sbde#include <sys/cdefs.h> 41123257Smarcel#include <sys/_null.h> 42102227Smike#include <sys/_types.h> 4333861Sbde 44103728Swollman#if __BSD_VISIBLE 45102227Smike#ifndef _RUNE_T_DECLARED 46102227Smiketypedef __rune_t rune_t; 47102227Smike#define _RUNE_T_DECLARED 4815483Sbde#endif 4915483Sbde#endif 5015483Sbde 51102227Smike#ifndef _SIZE_T_DECLARED 52102227Smiketypedef __size_t size_t; 53102227Smike#define _SIZE_T_DECLARED 541539Srgrimes#endif 551539Srgrimes 5699640Sobrien#ifndef __cplusplus 57102227Smike#ifndef _WCHAR_T_DECLARED 58102227Smiketypedef __wchar_t wchar_t; 59102227Smike#define _WCHAR_T_DECLARED 601539Srgrimes#endif 6199640Sobrien#endif 621539Srgrimes 631539Srgrimestypedef struct { 64103766Sbde int quot; /* quotient */ 65103766Sbde int rem; /* remainder */ 661539Srgrimes} div_t; 671539Srgrimes 681539Srgrimestypedef struct { 69103766Sbde long quot; 70103766Sbde long rem; 711539Srgrimes} ldiv_t; 721539Srgrimes 731539Srgrimes#define EXIT_FAILURE 1 741539Srgrimes#define EXIT_SUCCESS 0 751539Srgrimes 761539Srgrimes#define RAND_MAX 0x7fffffff 771539Srgrimes 781539Srgrimesextern int __mb_cur_max; 791539Srgrimes#define MB_CUR_MAX __mb_cur_max 801539Srgrimes 811539Srgrimes__BEGIN_DECLS 8293032Simpvoid abort(void) __dead2; 83153684Sphkvoid abort2(const char *, int, void **) __dead2; 8493032Simpint abs(int) __pure2; 8593032Simpint atexit(void (*)(void)); 8693032Simpdouble atof(const char *); 8793032Simpint atoi(const char *); 8893032Simplong atol(const char *); 8993032Simpvoid *bsearch(const void *, const void *, size_t, 9093032Simp size_t, int (*)(const void *, const void *)); 91187961Sdasvoid *calloc(size_t, size_t) __malloc_like; 9293032Simpdiv_t div(int, int) __pure2; 9393032Simpvoid exit(int) __dead2; 9493032Simpvoid free(void *); 9593032Simpchar *getenv(const char *); 9693032Simplong labs(long) __pure2; 9793032Simpldiv_t ldiv(long, long) __pure2; 98187961Sdasvoid *malloc(size_t) __malloc_like; 99103728Swollmanint mblen(const char *, size_t); 100103766Sbdesize_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 101103728Swollmanint mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 10293032Simpvoid qsort(void *, size_t, size_t, 10393032Simp int (*)(const void *, const void *)); 10493032Simpint rand(void); 10593032Simpvoid *realloc(void *, size_t); 10693032Simpvoid srand(unsigned); 107103766Sbdedouble strtod(const char * __restrict, char ** __restrict); 108112163Sdasfloat strtof(const char * __restrict, char ** __restrict); 109103766Sbdelong strtol(const char * __restrict, char ** __restrict, int); 110112163Sdaslong double 111112163Sdas strtold(const char * __restrict, char ** __restrict); 1121539Srgrimesunsigned long 113103012Stjr strtoul(const char * __restrict, char ** __restrict, int); 11493032Simpint system(const char *); 11593032Simpint wctomb(char *, wchar_t); 116103012Stjrsize_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 1171539Srgrimes 118103728Swollman/* 119103728Swollman * Functions added in C99 which we make conditionally available in the 120103728Swollman * BSD^C89 namespace if the compiler supports `long long'. 121103728Swollman * The #if test is more complicated than it ought to be because 122103728Swollman * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 123103728Swollman * is not supported in the compilation environment (which therefore means 124103728Swollman * that it can't really be ISO C99). 125103728Swollman * 126103728Swollman * (The only other extension made by C99 in thie header is _Exit().) 127103728Swollman */ 128103728Swollman#if __ISO_C_VISIBLE >= 1999 129103728Swollman#ifdef __LONG_LONG_SUPPORTED 130103728Swollman/* LONGLONG */ 131103728Swollmantypedef struct { 132103728Swollman long long quot; 133103728Swollman long long rem; 134103728Swollman} lldiv_t; 13569201Sphk 136103728Swollman/* LONGLONG */ 137103728Swollmanlong long 138103728Swollman atoll(const char *); 139103728Swollman/* LONGLONG */ 140103728Swollmanlong long 141103728Swollman llabs(long long) __pure2; 142103728Swollman/* LONGLONG */ 143103728Swollmanlldiv_t lldiv(long long, long long) __pure2; 144103728Swollman/* LONGLONG */ 145103766Sbdelong long 146103766Sbde strtoll(const char * __restrict, char ** __restrict, int); 147103728Swollman/* LONGLONG */ 148103728Swollmanunsigned long long 149103766Sbde strtoull(const char * __restrict, char ** __restrict, int); 150103728Swollman#endif /* __LONG_LONG_SUPPORTED */ 151103728Swollman 152103766Sbdevoid _Exit(int) __dead2; 153103728Swollman#endif /* __ISO_C_VISIBLE >= 1999 */ 154103728Swollman 155103728Swollman/* 156103728Swollman * Extensions made by POSIX relative to C. We don't know yet which edition 157103728Swollman * of POSIX made these extensions, so assume they've always been there until 158103728Swollman * research can be done. 159103728Swollman */ 160103728Swollman#if __POSIX_VISIBLE /* >= ??? */ 161154250Sjasoneint posix_memalign(void **, size_t, size_t); /* (ADV) */ 162103728Swollmanint rand_r(unsigned *); /* (TSF) */ 16393032Simpint setenv(const char *, const char *, int); 164171195Sscfint unsetenv(const char *); 165103728Swollman#endif 1661539Srgrimes 167103728Swollman/* 168103728Swollman * The only changes to the XSI namespace in revision 6 were the deletion 169103728Swollman * of the ttyslot() and valloc() functions, which FreeBSD never declared 170103728Swollman * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 171103728Swollman * FreeBSD also does not have, and mktemp(), are to be deleted. 172103728Swollman */ 173103728Swollman#if __XSI_VISIBLE 174103728Swollman/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 175153707Strhodeslong a64l(const char *); 17693032Simpdouble drand48(void); 177103766Sbde/* char *ecvt(double, int, int * __restrict, int * __restrict); */ 17893032Simpdouble erand48(unsigned short[3]); 179103766Sbde/* char *fcvt(double, int, int * __restrict, int * __restrict); */ 180103766Sbde/* char *gcvt(double, int, int * __restrict, int * __restrict); */ 181103728Swollmanint getsubopt(char **, char *const *, char **); 182108574Sjmallettint grantpt(int); 183103728Swollmanchar *initstate(unsigned long /* XSI requires u_int */, char *, long); 18493032Simplong jrand48(unsigned short[3]); 185153707Strhodeschar *l64a(long); 18693032Simpvoid lcong48(unsigned short[7]); 18793032Simplong lrand48(void); 188103728Swollman#ifndef _MKSTEMP_DECLARED 189103728Swollmanint mkstemp(char *); 190103728Swollman#define _MKSTEMP_DECLARED 191103728Swollman#endif 192103728Swollman#ifndef _MKTEMP_DECLARED 193103728Swollmanchar *mktemp(char *); 194103766Sbde#define _MKTEMP_DECLARED 195103728Swollman#endif 19693032Simplong mrand48(void); 19793032Simplong nrand48(unsigned short[3]); 198108574Sjmallettint posix_openpt(int); 199108574Sjmallettchar *ptsname(int); 200171195Sscfint putenv(char *); 201103728Swollmanlong random(void); 202103728Swollmanchar *realpath(const char *, char resolved_path[]); 2037865Sbdeunsigned short 20493032Simp *seed48(unsigned short[3]); 205103728Swollman#ifndef _SETKEY_DECLARED 206103728Swollmanint setkey(const char *); 207103728Swollman#define _SETKEY_DECLARED 208103728Swollman#endif 209103728Swollmanchar *setstate(/* const */ char *); 21093032Simpvoid srand48(long); 211103728Swollmanvoid srandom(unsigned long); 212108574Sjmallettint unlockpt(int); 213103728Swollman#endif /* __XSI_VISIBLE */ 2144749Sats 215103728Swollman#if __BSD_VISIBLE 216103728Swollmanextern const char *_malloc_options; 217103766Sbdeextern void (*_malloc_message)(const char *, const char *, const char *, 218103766Sbde const char *); 219103728Swollman 220116397Sdes/* 221116397Sdes * The alloca() function can't be implemented in C, and on some 222116397Sdes * platforms it can't be implemented at all as a callable function. 223116397Sdes * The GNU C compiler provides a built-in alloca() which we can use; 224116397Sdes * in all other cases, provide a prototype, mainly to pacify various 225116397Sdes * incarnations of lint. On platforms where alloca() is not in libc, 226116397Sdes * programs which use it will fail to link when compiled with non-GNU 227116397Sdes * compilers. 228116397Sdes */ 229116831Sobrien#if __GNUC__ >= 2 || defined(__INTEL_COMPILER) 230116831Sobrien#undef alloca /* some GNU bits try to get cute and define this on their own */ 231116397Sdes#define alloca(sz) __builtin_alloca(sz) 232116831Sobrien#elif defined(lint) 233116831Sobrienvoid *alloca(size_t); 234116397Sdes#endif 235116397Sdes 23641927Sdt__uint32_t 23793032Simp arc4random(void); 238180658Sachevoid arc4random_addrandom(unsigned char *, int); 239180658Sachevoid arc4random_buf(void *, size_t); 24093032Simpvoid arc4random_stir(void); 241180689Sache__uint32_t 242180689Sache arc4random_uniform(__uint32_t); 243108445Sobrienchar *getbsize(int *, long *); 244103728Swollman /* getcap(3) functions */ 24593032Simpchar *cgetcap(char *, const char *, int); 24693032Simpint cgetclose(void); 24793032Simpint cgetent(char **, char **, const char *); 24893032Simpint cgetfirst(char **, char **); 24993032Simpint cgetmatch(const char *, const char *); 25093032Simpint cgetnext(char **, char **); 25193032Simpint cgetnum(char *, const char *, long *); 25293032Simpint cgetset(const char *); 25393032Simpint cgetstr(char *, const char *, char **); 25493032Simpint cgetustr(char *, const char *, char **); 2551539Srgrimes 25693032Simpint daemon(int, int); 257150052Sstefanfchar *devname(__dev_t, __mode_t); 258150052Sstefanfchar *devname_r(__dev_t, __mode_t, char *, int); 25993032Simpint getloadavg(double [], int); 26088399Smike__const char * 26193032Simp getprogname(void); 2621539Srgrimes 26393032Simpint heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 264153707Strhodesint l64a_r(long, char *, int); 26593032Simpint mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 266103164Swollmanvoid qsort_r(void *, size_t, size_t, void *, 267103164Swollman int (*)(void *, const void *, const void *)); 26893032Simpint radixsort(const unsigned char **, int, const unsigned char *, 26993032Simp unsigned); 27093032Simpvoid *reallocf(void *, size_t); 271139922Stjrint rpmatch(const char *); 27293032Simpvoid setprogname(const char *); 273103164Swollmanint sradixsort(const unsigned char **, int, const unsigned char *, 274103164Swollman unsigned); 27593032Simpvoid sranddev(void); 27693032Simpvoid srandomdev(void); 277156707Sandrelong long 278156707Sandre strtonum(const char *, long long, long long, const char **); 279103728Swollman 280103728Swollman/* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 281103766Sbde__int64_t 282103766Sbde strtoq(const char *, char **, int); 28341927Sdt__uint64_t 28493032Simp strtouq(const char *, char **, int); 285126136Sache 286126136Sacheextern char *suboptarg; /* getsubopt(3) external variable */ 287103728Swollman#endif /* __BSD_VISIBLE */ 2881539Srgrimes__END_DECLS 2891539Srgrimes 2907865Sbde#endif /* !_STDLIB_H_ */ 291