stdlib.h revision 1.62 1 /* $NetBSD: stdlib.h,v 1.62 2003/04/28 23:16:14 bjh21 Exp $ */
2
3 /*-
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
36 */
37
38 #ifndef _STDLIB_H_
39 #define _STDLIB_H_
40
41 #include <sys/cdefs.h>
42 #include <sys/featuretest.h>
43
44 #if defined(_NETBSD_SOURCE)
45 #include <sys/types.h> /* for quad_t, etc. */
46 #endif
47
48 #include <machine/ansi.h>
49
50 #ifdef _BSD_SIZE_T_
51 typedef _BSD_SIZE_T_ size_t;
52 #undef _BSD_SIZE_T_
53 #endif
54
55 #ifdef _BSD_WCHAR_T_
56 typedef _BSD_WCHAR_T_ wchar_t;
57 #undef _BSD_WCHAR_T_
58 #endif
59
60 typedef struct {
61 int quot; /* quotient */
62 int rem; /* remainder */
63 } div_t;
64
65 typedef struct {
66 long quot; /* quotient */
67 long rem; /* remainder */
68 } ldiv_t;
69
70 #if !defined(_ANSI_SOURCE) && \
71 (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
72 defined(_NETBSD_SOURCE))
73 typedef struct {
74 /* LONGLONG */
75 long long int quot; /* quotient */
76 /* LONGLONG */
77 long long int rem; /* remainder */
78 } lldiv_t;
79 #endif
80
81 #if defined(_NETBSD_SOURCE)
82 typedef struct {
83 quad_t quot; /* quotient */
84 quad_t rem; /* remainder */
85 } qdiv_t;
86 #endif
87
88
89 #include <sys/null.h>
90
91 #define EXIT_FAILURE 1
92 #define EXIT_SUCCESS 0
93
94 #define RAND_MAX 0x7fffffff
95
96 extern size_t __mb_cur_max;
97 #define MB_CUR_MAX __mb_cur_max
98
99 __BEGIN_DECLS
100 __dead void _Exit __P((int)) __attribute__((__noreturn__));
101 __dead void abort __P((void)) __attribute__((__noreturn__));
102 __pure int abs __P((int));
103 int atexit __P((void (*)(void)));
104 double atof __P((const char *));
105 int atoi __P((const char *));
106 long atol __P((const char *));
107 #ifndef __BSEARCH_DECLARED
108 #define __BSEARCH_DECLARED
109 /* also in search.h */
110 void *bsearch __P((const void *, const void *, size_t, size_t,
111 int (*)(const void *, const void *)));
112 #endif /* __BSEARCH_DECLARED */
113 void *calloc __P((size_t, size_t));
114 div_t div __P((int, int));
115 __dead void exit __P((int)) __attribute__((__noreturn__));
116 void free __P((void *));
117 __aconst char *getenv __P((const char *));
118 __pure long
119 labs __P((long));
120 ldiv_t ldiv __P((long, long));
121 void *malloc __P((size_t));
122 void qsort __P((void *, size_t, size_t,
123 int (*)(const void *, const void *)));
124 int rand __P((void));
125 void *realloc __P((void *, size_t));
126 void srand __P((unsigned));
127 double strtod __P((const char * __restrict, char ** __restrict));
128 long strtol __P((const char * __restrict, char ** __restrict, int));
129 unsigned long
130 strtoul __P((const char * __restrict, char ** __restrict, int));
131 int system __P((const char *));
132
133 /* These are currently just stubs. */
134 int mblen __P((const char *, size_t));
135 size_t mbstowcs __P((wchar_t * __restrict, const char * __restrict, size_t));
136 int wctomb __P((char *, wchar_t));
137 int mbtowc __P((wchar_t * __restrict, const char * __restrict, size_t));
138 size_t wcstombs __P((char * __restrict, const wchar_t * __restrict, size_t));
139
140 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
141 defined(_NETBSD_SOURCE)
142
143
144 /*
145 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
146 */
147 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
148 defined(_REENTRANT) || defined(_NETBSD_SOURCE)
149 int rand_r __P((unsigned int *));
150 #endif
151
152
153 /*
154 * X/Open Portability Guide >= Issue 4
155 */
156 #if (_XOPEN_SOURCE - 0) >= 4 || defined(_NETBSD_SOURCE)
157 double drand48 __P((void));
158 double erand48 __P((unsigned short[3]));
159 long jrand48 __P((unsigned short[3]));
160 void lcong48 __P((unsigned short[7]));
161 long lrand48 __P((void));
162 long mrand48 __P((void));
163 long nrand48 __P((unsigned short[3]));
164 unsigned short *
165 seed48 __P((unsigned short[3]));
166 void srand48 __P((long));
167
168 int putenv __P((const char *));
169 #endif
170
171
172 /*
173 * X/Open Portability Guide >= Issue 4 Version 2
174 */
175 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
176 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
177 long a64l __P((const char *));
178 char *l64a __P((long));
179
180 char *initstate __P((unsigned long, char *, size_t));
181 long random __P((void));
182 char *setstate __P((char *));
183 void srandom __P((unsigned long));
184
185 char *mkdtemp __P((char *));
186 int mkstemp __P((char *));
187 #ifndef __AUDIT__
188 char *mktemp __P((char *));
189 #endif
190
191 int setkey __P((const char *));
192
193 char *realpath __P((const char *, char *));
194
195 int ttyslot __P((void));
196
197 void *valloc __P((size_t)); /* obsoleted by malloc() */
198 #endif
199
200 /*
201 * ISO C99
202 */
203 #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
204 defined(_NETBSD_SOURCE)
205 /* LONGLONG */
206 long long int atoll __P((const char *));
207 /* LONGLONG */
208 long long int llabs __P((long long int));
209 /* LONGLONG */
210 lldiv_t lldiv __P((long long int, long long int));
211 /* LONGLONG */
212 long long int strtoll __P((const char * __restrict, char ** __restrict, int));
213 /* LONGLONG */
214 unsigned long long int
215 strtoull __P((const char * __restrict, char ** __restrict,
216 int));
217 #endif
218
219 /*
220 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
221 */
222 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \
223 defined(_NETBSD_SOURCE)
224 int setenv __P((const char *, const char *, int));
225 #ifdef __LIBC12_SOURCE__
226 void unsetenv __P((const char *));
227 int __unsetenv13 __P((const char *));
228 #else
229 int unsetenv __P((const char *)) __RENAME(__unsetenv13);
230 #endif
231 #endif
232
233 /*
234 * Implementation-defined extensions
235 */
236 #if defined(_NETBSD_SOURCE)
237 #if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2)
238 void *alloca __P((int)); /* built-in for gcc */
239 #else
240 void *alloca __P((size_t));
241 #endif /* __GNUC__ */
242
243 u_int32_t arc4random __P((void));
244 void arc4random_stir __P((void));
245 void arc4random_addrandom __P((u_char *, int));
246 char *getbsize __P((int *, long *));
247 char *cgetcap __P((char *, const char *, int));
248 int cgetclose __P((void));
249 int cgetent __P((char **, char **, const char *));
250 int cgetfirst __P((char **, char **));
251 int cgetmatch __P((const char *, const char *));
252 int cgetnext __P((char **, char **));
253 int cgetnum __P((char *, const char *, long *));
254 int cgetset __P((const char *));
255 int cgetstr __P((char *, const char *, char **));
256 int cgetustr __P((char *, const char *, char **));
257
258 int daemon __P((int, int));
259 __aconst char *devname __P((dev_t, mode_t));
260 int getloadavg __P((double [], int));
261
262 void cfree __P((void *));
263
264 int heapsort __P((void *, size_t, size_t,
265 int (*)(const void *, const void *)));
266 int mergesort __P((void *, size_t, size_t,
267 int (*)(const void *, const void *)));
268 int radixsort __P((const unsigned char **, int, const unsigned char *,
269 unsigned));
270 int sradixsort __P((const unsigned char **, int, const unsigned char *,
271 unsigned));
272
273 void setproctitle __P((const char *, ...))
274 __attribute__((__format__(__printf__, 1, 2)));
275 const char *getprogname __P((void)) __attribute__((__const__));
276 void setprogname __P((const char *));
277
278 quad_t qabs __P((quad_t));
279 quad_t strtoq __P((const char * __restrict, char ** __restrict, int));
280 u_quad_t strtouq __P((const char * __restrict, char ** __restrict, int));
281
282 /* LONGLONG */
283 long long strsuftoll(const char *, const char *, long long, long long);
284 /* LONGLONG */
285 long long strsuftollx(const char *, const char *, long long, long long,
286 char *, size_t);
287
288 int l64a_r __P((long, char *, int));
289
290 size_t shquote __P((const char *arg, char *buf, size_t bufsize));
291 size_t shquotev __P((int argc, char * const * argv, char *buf,
292 size_t bufsize));
293 #endif /* _NETBSD_SOURCE */
294 #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
295
296 #if defined(_NETBSD_SOURCE)
297 qdiv_t qdiv __P((quad_t, quad_t));
298 #endif
299 __END_DECLS
300
301 #endif /* !_STDLIB_H_ */
302