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