1 /* $NetBSD: stdlib.h,v 1.115 2015/02/17 20:33:40 joerg Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
37 #include <sys/cdefs.h>
38 #include <sys/featuretest.h>
40 #if defined(_NETBSD_SOURCE)
41 #include <sys/types.h> /* for quad_t, etc. */
44 #include <machine/ansi.h>
47 typedef _BSD_SIZE_T_
size_t;
51 #if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
52 typedef _BSD_WCHAR_T_
wchar_t;
57 int quot
; /* quotient */
58 int rem
; /* remainder */
62 long quot
; /* quotient */
63 long rem
; /* remainder */
66 #if !defined(_ANSI_SOURCE) && \
67 (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
68 (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))
71 long long int quot
; /* quotient */
73 long long int rem
; /* remainder */
77 #if defined(_NETBSD_SOURCE)
79 quad_t quot
; /* quotient */
80 quad_t rem
; /* remainder */
87 #define EXIT_FAILURE 1
88 #define EXIT_SUCCESS 0
90 #define RAND_MAX 0x7fffffff
92 extern size_t __mb_cur_max
;
93 #define MB_CUR_MAX __mb_cur_max
96 __dead
void _Exit(int);
97 __dead
void abort(void);
99 int atexit(void (*)(void));
100 double atof(const char *);
101 int atoi(const char *);
102 long atol(const char *);
103 #ifndef __BSEARCH_DECLARED
104 #define __BSEARCH_DECLARED
105 /* also in search.h */
106 void *bsearch(const void *, const void *, size_t, size_t,
107 int (*)(const void *, const void *));
108 #endif /* __BSEARCH_DECLARED */
109 void *calloc(size_t, size_t);
111 __dead
void exit(int);
113 __aconst
char *getenv(const char *);
116 ldiv_t ldiv(long, long);
117 void *malloc(size_t);
118 void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
120 void *realloc(void *, size_t);
121 void srand(unsigned);
122 double strtod(const char * __restrict
, char ** __restrict
);
123 long strtol(const char * __restrict
, char ** __restrict
, int);
125 strtoul(const char * __restrict
, char ** __restrict
, int);
126 #ifdef _OPENBSD_SOURCE
127 long long strtonum(const char *, long long, long long, const char **);
128 void *reallocarray(void *, size_t, size_t);
130 int system(const char *);
132 /* These are currently just stubs. */
133 int mblen(const char *, size_t);
134 size_t mbstowcs(wchar_t * __restrict
, const char * __restrict
, size_t);
135 int wctomb(char *, wchar_t);
136 int mbtowc(wchar_t * __restrict
, const char * __restrict
, size_t);
137 size_t wcstombs(char * __restrict
, const wchar_t * __restrict
, size_t);
139 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
140 defined(_NETBSD_SOURCE)
144 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
146 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
147 defined(_REENTRANT) || defined(_NETBSD_SOURCE)
148 int rand_r(unsigned int *);
153 * X/Open Portability Guide >= Issue 4
155 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
156 double drand48(void);
157 double erand48(unsigned short[3]);
158 long jrand48(unsigned short[3]);
159 void lcong48(unsigned short[7]);
162 long nrand48(unsigned short[3]);
164 seed48(unsigned short[3]);
167 #ifndef __LIBC12_SOURCE__
168 int putenv(char *) __RENAME(__putenv50
);
174 * X/Open Portability Guide >= Issue 4 Version 2
176 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
177 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
178 long a64l(const char *);
182 char *setstate(char *);
183 #ifndef __LIBC12_SOURCE__
184 char *initstate(unsigned int, char *, size_t) __RENAME(__initstate60
);
185 void srandom(unsigned int) __RENAME(__srandom60
);
187 #ifdef _NETBSD_SOURCE
188 #define RANDOM_MAX 0x7fffffff /* (((long)1 << 31) - 1) */
189 int mkostemp(char *, int);
190 int mkostemps(char *, int, int);
193 char *mkdtemp(char *);
201 int setkey(const char *);
203 char *realpath(const char * __restrict
, char * __restrict
);
207 void *valloc(size_t); /* obsoleted by malloc() */
217 #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
218 defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L
221 long long int atoll(const char *);
223 long long int llabs(long long int);
225 lldiv_t
lldiv(long long int, long long int);
227 long long int strtoll(const char * __restrict
, char ** __restrict
, int);
229 unsigned long long int
230 strtoull(const char * __restrict
, char ** __restrict
, int);
231 float strtof(const char * __restrict
, char ** __restrict
);
232 long double strtold(const char * __restrict
, char ** __restrict
);
235 #if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L || \
236 defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L
237 int at_quick_exit(void (*)(void));
238 __dead
void quick_exit(int);
242 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
244 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \
245 defined(_NETBSD_SOURCE)
246 int setenv(const char *, const char *, int);
247 #ifndef __LIBC12_SOURCE__
248 int unsetenv(const char *) __RENAME(__unsetenv13
);
251 int posix_openpt(int);
252 int posix_memalign(void **, size_t, size_t);
256 * Implementation-defined extensions
258 #if defined(_NETBSD_SOURCE)
259 #if defined(alloca) && (alloca == __builtin_alloca) && \
260 defined(__GNUC__) && (__GNUC__ < 2)
261 void *alloca(int); /* built-in for gcc */
262 #elif defined(__PCC__) && !defined(__GNUC__)
263 #define alloca(size) __builtin_alloca(size)
265 void *alloca(size_t);
266 #endif /* __GNUC__ */
268 uint32_t arc4random(void);
269 void arc4random_stir(void);
270 void arc4random_buf(void *, size_t);
271 uint32_t arc4random_uniform(uint32_t);
272 void arc4random_addrandom(u_char
*, int);
273 char *getbsize(int *, long *);
274 char *cgetcap(char *, const char *, int);
276 int cgetent(char **, const char * const *, const char *);
277 int cgetfirst(char **, const char * const *);
278 int cgetmatch(const char *, const char *);
279 int cgetnext(char **, const char * const *);
280 int cgetnum(char *, const char *, long *);
281 int cgetset(const char *);
282 int cgetstr(char *, const char *, char **);
283 int cgetustr(char *, const char *, char **);
284 void csetexpandtc(int);
286 int daemon(int, int);
287 int devname_r(dev_t
, mode_t
, char *, size_t);
288 #ifndef __LIBC12_SOURCE__
289 __aconst
char *devname(dev_t
, mode_t
) __RENAME(__devname50
);
292 #define HN_DECIMAL 0x01
293 #define HN_NOSPACE 0x02
295 #define HN_DIVISOR_1000 0x08
297 #define HN_GETSCALE 0x10
298 #define HN_AUTOSCALE 0x20
300 int humanize_number(char *, size_t, int64_t, const char *, int, int);
301 int dehumanize_number(const char *, int64_t *);
303 devmajor_t
getdevmajor(const char *, mode_t
);
304 int getloadavg(double [], int);
306 int getenv_r(const char *, char *, size_t);
310 int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
311 int mergesort(void *, size_t, size_t,
312 int (*)(const void *, const void *));
313 int ptsname_r(int, char *, size_t);
314 int radixsort(const unsigned char **, int, const unsigned char *,
316 int sradixsort(const unsigned char **, int, const unsigned char *,
319 void mi_vector_hash(const void * __restrict
, size_t, uint32_t,
322 void setproctitle(const char *, ...)
324 const char *getprogname(void) __constfunc
;
325 void setprogname(const char *);
328 quad_t
strtoq(const char * __restrict
, char ** __restrict
, int);
329 u_quad_t
strtouq(const char * __restrict
, char ** __restrict
, int);
332 long long strsuftoll(const char *, const char *, long long, long long);
334 long long strsuftollx(const char *, const char *, long long, long long,
337 int l64a_r(long, char *, int);
339 size_t shquote(const char *, char *, size_t);
340 size_t shquotev(int, char * const *, char *, size_t);
342 int reallocarr(void *, size_t, size_t);
343 #endif /* _NETBSD_SOURCE */
344 #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
346 #if defined(_NETBSD_SOURCE)
347 qdiv_t
qdiv(quad_t
, quad_t
);
350 #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
351 # ifndef __LOCALE_T_DECLARED
352 typedef struct _locale
*locale_t
;
353 # define __LOCALE_T_DECLARED
355 double strtod_l(const char * __restrict
, char ** __restrict
, locale_t
);
356 float strtof_l(const char * __restrict
, char ** __restrict
, locale_t
);
357 long double strtold_l(const char * __restrict
, char ** __restrict
,
359 long strtol_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
361 strtoul_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
364 strtoll_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
366 unsigned long long int
367 strtoull_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
369 # if defined(_NETBSD_SOURCE)
370 quad_t
strtoq_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
371 u_quad_t
strtouq_l(const char * __restrict
, char ** __restrict
, int, locale_t
);
373 size_t _mb_cur_max_l(locale_t
);
374 #define MB_CUR_MAX_L(loc) _mb_cur_max_l(loc)
375 int mblen_l(const char *, size_t, locale_t
);
376 size_t mbstowcs_l(wchar_t * __restrict
, const char * __restrict
, size_t,
378 int wctomb_l(char *, wchar_t, locale_t
);
379 int mbtowc_l(wchar_t * __restrict
, const char * __restrict
, size_t,
381 size_t wcstombs_l(char * __restrict
, const wchar_t * __restrict
, size_t,
384 # endif /* _NETBSD_SOURCE */
385 #endif /* _POSIX_C_SOURCE >= 200809 || _NETBSD_SOURCE */
389 #endif /* !_STDLIB_H_ */