Annotation of src/include/stdlib.h, Revision 1.66
1.66 ! millert 1: /* $OpenBSD: stdlib.h,v 1.65 2015/07/14 19:05:11 millert Exp $ */
1.2 deraadt 2: /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
1.1 deraadt 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.
1.25 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 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:
1.35 millert 38: #include <sys/cdefs.h>
1.66 ! millert 39: #include <sys/_null.h>
1.36 millert 40: #include <machine/_types.h>
41: #if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */
1.1 deraadt 42: #include <sys/types.h>
43: #endif
44:
1.36 millert 45: #ifndef _SIZE_T_DEFINED_
46: #define _SIZE_T_DEFINED_
47: typedef __size_t size_t;
1.1 deraadt 48: #endif
49:
1.11 espie 50: /* in C++, wchar_t is a built-in type */
1.36 millert 51: #if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus)
52: #define _WCHAR_T_DEFINED_
53: typedef __wchar_t wchar_t;
1.1 deraadt 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:
1.37 millert 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:
1.35 millert 73: #if __BSD_VISIBLE
1.1 deraadt 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:
1.33 espie 85: extern size_t __mb_cur_max;
86: #define MB_CUR_MAX __mb_cur_max
1.1 deraadt 87:
88: #include <sys/cdefs.h>
89:
1.18 millert 90: /*
91: * Some header files may define an abs macro.
92: * If defined, undef it to prevent a syntax error and issue a warning.
93: */
94: #ifdef abs
95: #undef abs
96: #warning abs macro collides with abs() prototype, undefining
97: #endif
98:
1.1 deraadt 99: __BEGIN_DECLS
1.16 millert 100: __dead void abort(void);
101: int abs(int);
1.17 millert 102: int atexit(void (*)(void));
1.16 millert 103: double atof(const char *);
104: int atoi(const char *);
105: long atol(const char *);
1.17 millert 106: void *bsearch(const void *, const void *, size_t, size_t,
107: int (*)(const void *, const void *));
1.16 millert 108: void *calloc(size_t, size_t);
109: div_t div(int, int);
110: __dead void exit(int);
1.30 millert 111: __dead void _Exit(int);
1.16 millert 112: void free(void *);
113: char *getenv(const char *);
114: long labs(long);
115: ldiv_t ldiv(long, long);
116: void *malloc(size_t);
1.57 deraadt 117: #if __BSD_VISIBLE
1.58 tedu 118: void *reallocarray(void *, size_t, size_t);
1.57 deraadt 119: #endif /* __BSD_VISIBLE */
1.17 millert 120: void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1.16 millert 121: int rand(void);
122: void *realloc(void *, size_t);
123: void srand(unsigned);
1.62 deraadt 124: void srand_deterministic(unsigned);
1.64 tedu 125: double strtod(const char *__restrict, char **__restrict);
126: float strtof(const char *__restrict, char **__restrict);
127: long strtol(const char *__restrict, char **__restrict, int);
1.45 martynas 128: long double
1.64 tedu 129: strtold(const char *__restrict, char **__restrict);
1.1 deraadt 130: unsigned long
1.64 tedu 131: strtoul(const char *__restrict, char **__restrict, int);
1.16 millert 132: int system(const char *);
1.1 deraadt 133:
134: /* these are currently just stubs */
1.16 millert 135: int mblen(const char *, size_t);
136: size_t mbstowcs(wchar_t *, const char *, size_t);
137: int wctomb(char *, wchar_t);
138: int mbtowc(wchar_t *, const char *, size_t);
139: size_t wcstombs(char *, const wchar_t *, size_t);
1.1 deraadt 140:
1.35 millert 141: /*
142: * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
143: */
1.50 guenther 144: #if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || defined(_REENTRANT)
1.35 millert 145: int rand_r(unsigned int *);
146: #endif
147:
148: #if __BSD_VISIBLE || __XPG_VISIBLE >= 400
149: double drand48(void);
150: double erand48(unsigned short[3]);
151: long jrand48(unsigned short[3]);
152: void lcong48(unsigned short[7]);
1.62 deraadt 153: void lcong48_deterministic(unsigned short[7]);
1.35 millert 154: long lrand48(void);
155: long mrand48(void);
156: long nrand48(unsigned short[3]);
157: unsigned short *seed48(unsigned short[3]);
1.62 deraadt 158: unsigned short *seed48_deterministic(unsigned short[3]);
1.35 millert 159: void srand48(long);
1.62 deraadt 160: void srand48_deterministic(long);
1.35 millert 161:
1.46 millert 162: int putenv(char *);
1.35 millert 163: #endif
164:
1.50 guenther 165: /*
166: * XSI functions marked LEGACY in IEEE Std 1003.1-2001 (POSIX) and
167: * removed in IEEE Std 1003.1-2008
168: */
169: #if __BSD_VISIBLE || __XPG_VISIBLE < 700
170: char *ecvt(double, int, int *, int *);
171: char *fcvt(double, int, int *, int *);
172: char *gcvt(double, int, char *);
173: #if __BSD_VISIBLE || __XPG_VISIBLE >= 420
174: char *mktemp(char *);
175: #endif
176: #endif /* __BSD_VISIBLE || __XPG_VISIBLE < 700 */
177:
1.35 millert 178: #if __BSD_VISIBLE || __XPG_VISIBLE >= 420
179: long a64l(const char *);
180: char *l64a(long);
181:
182: char *initstate(unsigned int, char *, size_t)
183: __attribute__((__bounded__ (__string__,2,3)));
184: long random(void);
1.50 guenther 185: char *setstate(char *);
1.35 millert 186: void srandom(unsigned int);
1.62 deraadt 187: void srandom_deterministic(unsigned int);
1.35 millert 188:
1.56 martynas 189: char *realpath(const char *, char *)
190: __attribute__((__bounded__ (__minbytes__,2,1024)));
1.35 millert 191:
1.50 guenther 192: /*
193: * XSI functions marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001
194: */
195: #if __BSD_VISIBLE || __XPG_VISIBLE < 600
1.35 millert 196: int ttyslot(void);
197: void *valloc(size_t); /* obsoleted by malloc() */
1.50 guenther 198: #endif
1.35 millert 199: #endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
200:
201: /*
1.50 guenther 202: * 4.4BSD, then XSI in XPG4.2, then added to POSIX base in IEEE Std 1003.1-2008
203: */
204: #if __BSD_VISIBLE || __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
205: int mkstemp(char *);
206: #endif
207:
208: /*
1.35 millert 209: * ISO C99
210: */
1.37 millert 211: #if __ISO_C_VISIBLE >= 1999
1.35 millert 212: long long
213: atoll(const char *);
214: long long
215: llabs(long long);
1.39 djm 216: lldiv_t
217: lldiv(long long, long long);
1.35 millert 218: long long
1.64 tedu 219: strtoll(const char *__restrict, char **__restrict, int);
1.35 millert 220: unsigned long long
1.64 tedu 221: strtoull(const char *__restrict, char **__restrict, int);
1.35 millert 222: #endif
223:
224: /*
225: * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
226: */
1.50 guenther 227: #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
228: int posix_memalign(void **, size_t, size_t);
1.35 millert 229: int setenv(const char *, const char *, int);
1.46 millert 230: int unsetenv(const char *);
1.51 millert 231: #endif
232: #if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200112
233: char *ptsname(int);
234: int grantpt(int);
235: int unlockpt(int);
236: #endif
237: #if __POSIX_VISIBLE >= 200112
238: int posix_openpt(int);
1.35 millert 239: #endif
240:
1.50 guenther 241: /*
242: * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX)
243: */
244: #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
245: char *mkdtemp(char *);
246: #endif
247:
1.55 millert 248: #if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
1.54 millert 249: int getsubopt(char **, char * const *, char **);
250: #endif
251:
1.60 guenther 252: /*
253: * The Open Group Base Specifications, post-Issue 7
254: */
255: #if __BSD_VISIBLE
256: int mkostemp(char *, int);
257: #endif
258:
1.35 millert 259: #if __BSD_VISIBLE
1.63 tedu 260: #define alloca(n) __builtin_alloca(n)
1.1 deraadt 261:
1.16 millert 262: char *getbsize(int *, long *);
263: char *cgetcap(char *, const char *, int);
264: int cgetclose(void);
265: int cgetent(char **, char **, const char *);
266: int cgetfirst(char **, char **);
267: int cgetmatch(char *, const char *);
268: int cgetnext(char **, char **);
269: int cgetnum(char *, const char *, long *);
270: int cgetset(const char *);
271: int cgetusedb(int);
272: int cgetstr(char *, const char *, char **);
273: int cgetustr(char *, const char *, char **);
274:
275: int daemon(int, int);
1.65 millert 276: char *devname(dev_t, mode_t);
1.16 millert 277: int getloadavg(double [], int);
1.52 ajacouto 278:
279: const char *
280: getprogname(void);
281: void setprogname(const char *);
1.1 deraadt 282:
283: extern char *suboptarg; /* getsubopt(3) external variable */
284:
1.35 millert 285: int mkstemps(char *, int);
1.60 guenther 286: int mkostemps(char *, int, int);
1.35 millert 287:
1.17 millert 288: int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
289: int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
290: int radixsort(const unsigned char **, int, const unsigned char *,
291: unsigned);
292: int sradixsort(const unsigned char **, int, const unsigned char *,
293: unsigned);
1.1 deraadt 294:
1.16 millert 295: void srandomdev(void);
1.35 millert 296: long long
297: strtonum(const char *, long long, long long, const char **);
1.16 millert 298:
299: void setproctitle(const char *, ...)
1.15 krw 300: __attribute__((__format__ (__printf__, 1, 2)));
1.1 deraadt 301:
1.16 millert 302: quad_t qabs(quad_t);
303: qdiv_t qdiv(quad_t, quad_t);
1.64 tedu 304: quad_t strtoq(const char *__restrict, char **__restrict, int);
305: u_quad_t strtouq(const char *__restrict, char **__restrict, int);
1.16 millert 306:
1.59 beck 307: uint32_t arc4random(void);
308: uint32_t arc4random_uniform(uint32_t);
1.41 otto 309: void arc4random_buf(void *, size_t)
310: __attribute__((__bounded__ (__string__,1,2)));
311:
1.35 millert 312: #endif /* __BSD_VISIBLE */
1.1 deraadt 313:
314: __END_DECLS
315:
316: #endif /* _STDLIB_H_ */