1 /* $OpenBSD: stdlib.h,v 1.67 2016/09/20 21:10:22 fcambus Exp $ */ 2 /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ 3 4 /*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)stdlib.h 5.13 (Berkeley) 6/4/91 33 */ 34 35 #ifndef _STDLIB_H_ 36 #define _STDLIB_H_ 37 38 #include <sys/cdefs.h> 39 #include <sys/_null.h> 40 #include <machine/_types.h> 41 #if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */ 42 #include <sys/types.h> 43 #endif 44 45 #ifndef _SIZE_T_DEFINED_ 46 #define _SIZE_T_DEFINED_ 47 typedef __size_t size_t; 48 #endif 49 50 /* in C++, wchar_t is a built-in type */ 51 #if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) 52 #define _WCHAR_T_DEFINED_ 53 typedef __wchar_t wchar_t; 54 #endif 55 56 typedef struct { 57 int quot; /* quotient */ 58 int rem; /* remainder */ 59 } div_t; 60 61 typedef struct { 62 long quot; /* quotient */ 63 long rem; /* remainder */ 64 } ldiv_t; 65 66 #if __ISO_C_VISIBLE >= 1999 67 typedef struct { 68 long long quot; /* quotient */ 69 long long rem; /* remainder */ 70 } lldiv_t; 71 #endif 72 73 #if __BSD_VISIBLE 74 typedef struct { 75 quad_t quot; /* quotient */ 76 quad_t rem; /* remainder */ 77 } qdiv_t; 78 #endif 79 80 #define EXIT_FAILURE 1 81 #define EXIT_SUCCESS 0 82 83 #define RAND_MAX 0x7fffffff 84 85 extern size_t __mb_cur_max; 86 #define MB_CUR_MAX __mb_cur_max 87 88 /* 89 * Some header files may define an abs macro. 90 * If defined, undef it to prevent a syntax error and issue a warning. 91 */ 92 #ifdef abs 93 #undef abs 94 #warning abs macro collides with abs() prototype, undefining 95 #endif 96 97 __BEGIN_DECLS 98 __dead void abort(void); 99 int abs(int); 100 int atexit(void (*)(void)); 101 double atof(const char *); 102 int atoi(const char *); 103 long atol(const char *); 104 void *bsearch(const void *, const void *, size_t, size_t, 105 int (*)(const void *, const void *)); 106 void *calloc(size_t, size_t); 107 div_t div(int, int); 108 __dead void exit(int); 109 __dead void _Exit(int); 110 void free(void *); 111 char *getenv(const char *); 112 long labs(long); 113 ldiv_t ldiv(long, long); 114 void *malloc(size_t); 115 #if __BSD_VISIBLE 116 void *reallocarray(void *, size_t, size_t); 117 #endif /* __BSD_VISIBLE */ 118 void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 119 int rand(void); 120 void *realloc(void *, size_t); 121 void srand(unsigned); 122 void srand_deterministic(unsigned); 123 double strtod(const char *__restrict, char **__restrict); 124 float strtof(const char *__restrict, char **__restrict); 125 long strtol(const char *__restrict, char **__restrict, int); 126 long double 127 strtold(const char *__restrict, char **__restrict); 128 unsigned long 129 strtoul(const char *__restrict, char **__restrict, int); 130 int system(const char *); 131 132 /* these are currently just stubs */ 133 int mblen(const char *, size_t); 134 size_t mbstowcs(wchar_t *, const char *, size_t); 135 int wctomb(char *, wchar_t); 136 int mbtowc(wchar_t *, const char *, size_t); 137 size_t wcstombs(char *, const wchar_t *, size_t); 138 139 /* 140 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2 141 */ 142 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || defined(_REENTRANT) 143 int rand_r(unsigned int *); 144 #endif 145 146 #if __BSD_VISIBLE || __XPG_VISIBLE >= 400 147 double drand48(void); 148 double erand48(unsigned short[3]); 149 long jrand48(unsigned short[3]); 150 void lcong48(unsigned short[7]); 151 void lcong48_deterministic(unsigned short[7]); 152 long lrand48(void); 153 long mrand48(void); 154 long nrand48(unsigned short[3]); 155 unsigned short *seed48(unsigned short[3]); 156 unsigned short *seed48_deterministic(unsigned short[3]); 157 void srand48(long); 158 void srand48_deterministic(long); 159 160 int putenv(char *); 161 #endif 162 163 /* 164 * XSI functions marked LEGACY in IEEE Std 1003.1-2001 (POSIX) and 165 * removed in IEEE Std 1003.1-2008 166 */ 167 #if __BSD_VISIBLE || __XPG_VISIBLE < 700 168 char *ecvt(double, int, int *, int *); 169 char *fcvt(double, int, int *, int *); 170 char *gcvt(double, int, char *); 171 #if __BSD_VISIBLE || __XPG_VISIBLE >= 420 172 char *mktemp(char *); 173 #endif 174 #endif /* __BSD_VISIBLE || __XPG_VISIBLE < 700 */ 175 176 #if __BSD_VISIBLE || __XPG_VISIBLE >= 420 177 long a64l(const char *); 178 char *l64a(long); 179 180 char *initstate(unsigned int, char *, size_t) 181 __attribute__((__bounded__ (__string__,2,3))); 182 long random(void); 183 char *setstate(char *); 184 void srandom(unsigned int); 185 void srandom_deterministic(unsigned int); 186 187 char *realpath(const char *, char *) 188 __attribute__((__bounded__ (__minbytes__,2,1024))); 189 190 /* 191 * XSI functions marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 192 */ 193 #if __BSD_VISIBLE || __XPG_VISIBLE < 600 194 int ttyslot(void); 195 void *valloc(size_t); /* obsoleted by malloc() */ 196 #endif 197 #endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ 198 199 /* 200 * 4.4BSD, then XSI in XPG4.2, then added to POSIX base in IEEE Std 1003.1-2008 201 */ 202 #if __BSD_VISIBLE || __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 203 int mkstemp(char *); 204 #endif 205 206 /* 207 * ISO C99 208 */ 209 #if __ISO_C_VISIBLE >= 1999 210 long long 211 atoll(const char *); 212 long long 213 llabs(long long); 214 lldiv_t 215 lldiv(long long, long long); 216 long long 217 strtoll(const char *__restrict, char **__restrict, int); 218 unsigned long long 219 strtoull(const char *__restrict, char **__restrict, int); 220 #endif 221 222 /* 223 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX) 224 */ 225 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 226 int posix_memalign(void **, size_t, size_t); 227 int setenv(const char *, const char *, int); 228 int unsetenv(const char *); 229 #endif 230 #if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200112 231 char *ptsname(int); 232 int grantpt(int); 233 int unlockpt(int); 234 #endif 235 #if __POSIX_VISIBLE >= 200112 236 int posix_openpt(int); 237 #endif 238 239 /* 240 * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX) 241 */ 242 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 243 char *mkdtemp(char *); 244 #endif 245 246 #if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 247 int getsubopt(char **, char * const *, char **); 248 #endif 249 250 /* 251 * The Open Group Base Specifications, post-Issue 7 252 */ 253 #if __BSD_VISIBLE 254 int mkostemp(char *, int); 255 #endif 256 257 #if __BSD_VISIBLE 258 #define alloca(n) __builtin_alloca(n) 259 260 char *getbsize(int *, long *); 261 char *cgetcap(char *, const char *, int); 262 int cgetclose(void); 263 int cgetent(char **, char **, const char *); 264 int cgetfirst(char **, char **); 265 int cgetmatch(char *, const char *); 266 int cgetnext(char **, char **); 267 int cgetnum(char *, const char *, long *); 268 int cgetset(const char *); 269 int cgetusedb(int); 270 int cgetstr(char *, const char *, char **); 271 int cgetustr(char *, const char *, char **); 272 273 int daemon(int, int); 274 char *devname(dev_t, mode_t); 275 int getloadavg(double [], int); 276 277 const char * 278 getprogname(void); 279 void setprogname(const char *); 280 281 extern char *suboptarg; /* getsubopt(3) external variable */ 282 283 int mkstemps(char *, int); 284 int mkostemps(char *, int, int); 285 286 int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 287 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 288 int radixsort(const unsigned char **, int, const unsigned char *, 289 unsigned); 290 int sradixsort(const unsigned char **, int, const unsigned char *, 291 unsigned); 292 293 void srandomdev(void); 294 long long 295 strtonum(const char *, long long, long long, const char **); 296 297 void setproctitle(const char *, ...) 298 __attribute__((__format__ (__printf__, 1, 2))); 299 300 quad_t qabs(quad_t); 301 qdiv_t qdiv(quad_t, quad_t); 302 quad_t strtoq(const char *__restrict, char **__restrict, int); 303 u_quad_t strtouq(const char *__restrict, char **__restrict, int); 304 305 uint32_t arc4random(void); 306 uint32_t arc4random_uniform(uint32_t); 307 void arc4random_buf(void *, size_t) 308 __attribute__((__bounded__ (__string__,1,2))); 309 310 #endif /* __BSD_VISIBLE */ 311 312 __END_DECLS 313 314 #endif /* _STDLIB_H_ */ 315