stdlib.h revision 116397
1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 34 * $FreeBSD: head/include/stdlib.h 116397 2003-06-15 11:01:52Z des $ 35 */ 36 37#ifndef _STDLIB_H_ 38#define _STDLIB_H_ 39 40#include <sys/cdefs.h> 41#include <sys/_types.h> 42 43#if __BSD_VISIBLE 44#ifndef _RUNE_T_DECLARED 45typedef __rune_t rune_t; 46#define _RUNE_T_DECLARED 47#endif 48#endif 49 50#ifndef _SIZE_T_DECLARED 51typedef __size_t size_t; 52#define _SIZE_T_DECLARED 53#endif 54 55#ifndef __cplusplus 56#ifndef _WCHAR_T_DECLARED 57typedef __wchar_t wchar_t; 58#define _WCHAR_T_DECLARED 59#endif 60#endif 61 62typedef struct { 63 int quot; /* quotient */ 64 int rem; /* remainder */ 65} div_t; 66 67typedef struct { 68 long quot; 69 long rem; 70} ldiv_t; 71 72#ifndef NULL 73#define NULL 0 74#endif 75 76#define EXIT_FAILURE 1 77#define EXIT_SUCCESS 0 78 79#define RAND_MAX 0x7fffffff 80 81extern int __mb_cur_max; 82#define MB_CUR_MAX __mb_cur_max 83 84__BEGIN_DECLS 85void abort(void) __dead2; 86int abs(int) __pure2; 87int atexit(void (*)(void)); 88double atof(const char *); 89int atoi(const char *); 90long atol(const char *); 91void *bsearch(const void *, const void *, size_t, 92 size_t, int (*)(const void *, const void *)); 93void *calloc(size_t, size_t); 94div_t div(int, int) __pure2; 95void exit(int) __dead2; 96void free(void *); 97char *getenv(const char *); 98long labs(long) __pure2; 99ldiv_t ldiv(long, long) __pure2; 100void *malloc(size_t); 101int mblen(const char *, size_t); 102size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 103int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 104void qsort(void *, size_t, size_t, 105 int (*)(const void *, const void *)); 106int rand(void); 107void *realloc(void *, size_t); 108void srand(unsigned); 109double strtod(const char * __restrict, char ** __restrict); 110float strtof(const char * __restrict, char ** __restrict); 111long strtol(const char * __restrict, char ** __restrict, int); 112long double 113 strtold(const char * __restrict, char ** __restrict); 114unsigned long 115 strtoul(const char * __restrict, char ** __restrict, int); 116int system(const char *); 117int wctomb(char *, wchar_t); 118size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 119 120/* 121 * Functions added in C99 which we make conditionally available in the 122 * BSD^C89 namespace if the compiler supports `long long'. 123 * The #if test is more complicated than it ought to be because 124 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' 125 * is not supported in the compilation environment (which therefore means 126 * that it can't really be ISO C99). 127 * 128 * (The only other extension made by C99 in thie header is _Exit().) 129 */ 130#if __ISO_C_VISIBLE >= 1999 131#ifdef __LONG_LONG_SUPPORTED 132/* LONGLONG */ 133typedef struct { 134 long long quot; 135 long long rem; 136} lldiv_t; 137 138/* LONGLONG */ 139long long 140 atoll(const char *); 141/* LONGLONG */ 142long long 143 llabs(long long) __pure2; 144/* LONGLONG */ 145lldiv_t lldiv(long long, long long) __pure2; 146/* LONGLONG */ 147long long 148 strtoll(const char * __restrict, char ** __restrict, int); 149/* LONGLONG */ 150unsigned long long 151 strtoull(const char * __restrict, char ** __restrict, int); 152#endif /* __LONG_LONG_SUPPORTED */ 153 154void _Exit(int) __dead2; 155#endif /* __ISO_C_VISIBLE >= 1999 */ 156 157/* 158 * Extensions made by POSIX relative to C. We don't know yet which edition 159 * of POSIX made these extensions, so assume they've always been there until 160 * research can be done. 161 */ 162#if __POSIX_VISIBLE /* >= ??? */ 163/* int posix_memalign(void **, size_t, size_t); (ADV) */ 164int rand_r(unsigned *); /* (TSF) */ 165int setenv(const char *, const char *, int); 166void unsetenv(const char *); 167#endif 168 169/* 170 * The only changes to the XSI namespace in revision 6 were the deletion 171 * of the ttyslot() and valloc() functions, which FreeBSD never declared 172 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which 173 * FreeBSD also does not have, and mktemp(), are to be deleted. 174 */ 175#if __XSI_VISIBLE 176/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */ 177/* long a64l(const char *); */ 178double drand48(void); 179/* char *ecvt(double, int, int * __restrict, int * __restrict); */ 180double erand48(unsigned short[3]); 181/* char *fcvt(double, int, int * __restrict, int * __restrict); */ 182/* char *gcvt(double, int, int * __restrict, int * __restrict); */ 183#ifndef _GETSUBOPT_DECLARED 184int getsubopt(char **, char *const *, char **); 185#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