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$ 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 45 typedef __rune_t rune_t; 46 #define _RUNE_T_DECLARED 47 #endif 48 #endif 49 50 #ifndef _SIZE_T_DECLARED 51 typedef __size_t size_t; 52 #define _SIZE_T_DECLARED 53 #endif 54 55 #ifndef __cplusplus 56 #ifndef _WCHAR_T_DECLARED 57 typedef __wchar_t wchar_t; 58 #define _WCHAR_T_DECLARED 59 #endif 60 #endif 61 62 typedef struct { 63 int quot; /* quotient */ 64 int rem; /* remainder */ 65 } div_t; 66 67 typedef 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 81 extern int __mb_cur_max; 82 #define MB_CUR_MAX __mb_cur_max 83 84 __BEGIN_DECLS 85 void abort(void) __dead2; 86 int abs(int) __pure2; 87 int atexit(void (*)(void)); 88 double atof(const char *); 89 int atoi(const char *); 90 long atol(const char *); 91 void *bsearch(const void *, const void *, size_t, 92 size_t, int (*)(const void *, const void *)); 93 void *calloc(size_t, size_t); 94 div_t div(int, int) __pure2; 95 void exit(int) __dead2; 96 void free(void *); 97 char *getenv(const char *); 98 long labs(long) __pure2; 99 ldiv_t ldiv(long, long) __pure2; 100 void *malloc(size_t); 101 int mblen(const char *, size_t); 102 size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 103 int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 104 void qsort(void *, size_t, size_t, 105 int (*)(const void *, const void *)); 106 int rand(void); 107 void *realloc(void *, size_t); 108 void srand(unsigned); 109 double strtod(const char * __restrict, char ** __restrict); 110 /* float strtof(const char * __restrict, char ** __restrict); */ 111 long strtol(const char * __restrict, char ** __restrict, int); 112 /* long double 113 strtold(const char * __restrict, char ** __restrict); */ 114 unsigned long 115 strtoul(const char * __restrict, char ** __restrict, int); 116 int system(const char *); 117 int wctomb(char *, wchar_t); 118 size_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 */ 133 typedef struct { 134 long long quot; 135 long long rem; 136 } lldiv_t; 137 138 /* LONGLONG */ 139 long long 140 atoll(const char *); 141 /* LONGLONG */ 142 long long 143 llabs(long long) __pure2; 144 /* LONGLONG */ 145 lldiv_t lldiv(long long, long long) __pure2; 146 /* LONGLONG */ 147 long long 148 strtoll(const char * __restrict, char ** __restrict, int); 149 /* LONGLONG */ 150 unsigned long long 151 strtoull(const char * __restrict, char ** __restrict, int); 152 #endif /* __LONG_LONG_SUPPORTED */ 153 154 void _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) */ 164 int rand_r(unsigned *); /* (TSF) */ 165 int setenv(const char *, const char *, int); 166 void 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 *); */ 178 double drand48(void); 179 /* char *ecvt(double, int, int * __restrict, int * __restrict); */ 180 double 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 184 int getsubopt(char **, char *const *, char **); 185 #define _GETSUBOPT_DECLARED 186 #endif 187 /* int grantpt(int); */ 188 char *initstate(unsigned long /* XSI requires u_int */, char *, long); 189 long jrand48(unsigned short[3]); 190 /* char *l64a(long); */ 191 void lcong48(unsigned short[7]); 192 long lrand48(void); 193 #ifndef _MKSTEMP_DECLARED 194 int mkstemp(char *); 195 #define _MKSTEMP_DECLARED 196 #endif 197 #ifndef _MKTEMP_DECLARED 198 char *mktemp(char *); 199 #define _MKTEMP_DECLARED 200 #endif 201 long mrand48(void); 202 long nrand48(unsigned short[3]); 203 /* int posix_openpt(int); */ 204 /* char *ptsname(int); */ 205 int putenv(const char *); 206 long random(void); 207 char *realpath(const char *, char resolved_path[]); 208 unsigned short 209 *seed48(unsigned short[3]); 210 #ifndef _SETKEY_DECLARED 211 int setkey(const char *); 212 #define _SETKEY_DECLARED 213 #endif 214 char *setstate(/* const */ char *); 215 void srand48(long); 216 void srandom(unsigned long); 217 /* int unlockpt(int); */ 218 #endif /* __XSI_VISIBLE */ 219 220 #if __BSD_VISIBLE 221 extern const char *_malloc_options; 222 extern void (*_malloc_message)(const char *, const char *, const char *, 223 const char *); 224 225 void *alloca(size_t); /* built-in for gcc */ 226 __uint32_t 227 arc4random(void); 228 void arc4random_addrandom(unsigned char *dat, int datlen); 229 void arc4random_stir(void); 230 char *getbsize(size_t *, long *); 231 /* getcap(3) functions */ 232 char *cgetcap(char *, const char *, int); 233 int cgetclose(void); 234 int cgetent(char **, char **, const char *); 235 int cgetfirst(char **, char **); 236 int cgetmatch(const char *, const char *); 237 int cgetnext(char **, char **); 238 int cgetnum(char *, const char *, long *); 239 int cgetset(const char *); 240 int cgetstr(char *, const char *, char **); 241 int cgetustr(char *, const char *, char **); 242 243 int daemon(int, int); 244 char *devname(int, int); 245 int getloadavg(double [], int); 246 __const char * 247 getprogname(void); 248 249 int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 250 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 251 void qsort_r(void *, size_t, size_t, void *, 252 int (*)(void *, const void *, const void *)); 253 int radixsort(const unsigned char **, int, const unsigned char *, 254 unsigned); 255 void *reallocf(void *, size_t); 256 void setprogname(const char *); 257 int sradixsort(const unsigned char **, int, const unsigned char *, 258 unsigned); 259 void sranddev(void); 260 void srandomdev(void); 261 262 /* Deprecated interfaces, to be removed in FreeBSD 6.0. */ 263 __int64_t 264 strtoq(const char *, char **, int); 265 __uint64_t 266 strtouq(const char *, char **, int); 267 #endif /* __BSD_VISIBLE */ 268 __END_DECLS 269 270 #endif /* !_STDLIB_H_ */ 271