nrelease - fix/improve livecd
[dragonfly.git] / include / stdlib.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
bc7a8293 13 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
5d0641a4 30 * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $
984263bc
MD
31 */
32
33#ifndef _STDLIB_H_
34#define _STDLIB_H_
35
36#include <sys/cdefs.h>
5d0641a4 37#include <sys/_null.h>
fa261b1d 38#include <sys/types.h>
3cfdabcf 39#ifndef __cplusplus
40#include <machine/wchar.h> /* for ___wchar_t */
41#endif
faed5989 42#if __BSD_VISIBLE
8f546928 43#include <malloc_np.h> /* for malloc_usable_size */
faed5989 44#endif
984263bc 45
5d0641a4 46#ifndef _SIZE_T_DECLARED
2d418273 47typedef __size_t size_t; /* _GCC_SIZE_T OK */
5d0641a4 48#define _SIZE_T_DECLARED
e2565a42 49#endif
984263bc 50
5d0641a4 51#ifndef __cplusplus
a81b3ef3 52#ifndef _WCHAR_T_DECLARED
3cfdabcf 53typedef ___wchar_t wchar_t; /* _GCC_WCHAR_T OK */
5d0641a4 54#define _WCHAR_T_DECLARED
984263bc 55#endif
984263bc 56#endif
e2565a42 57
086b156c 58#if __EXT1_VISIBLE
258eae18 59#ifndef _ERRNO_T_DECLARED
086b156c 60typedef int errno_t;
258eae18 61#define _ERRNO_T_DECLARED
086b156c
SW
62#endif
63#endif
64
984263bc 65typedef struct {
5d0641a4
PA
66 int quot; /* quotient */
67 int rem; /* remainder */
984263bc
MD
68} div_t;
69
70typedef struct {
5d0641a4
PA
71 long quot;
72 long rem;
984263bc
MD
73} ldiv_t;
74
984263bc
MD
75#define EXIT_FAILURE 1
76#define EXIT_SUCCESS 0
77
78#define RAND_MAX 0x7fffffff
79
0d5acd74
JM
80__BEGIN_DECLS
81#ifdef _XLOCALE_H_
82#include <xlocale/_stdlib.h>
83#endif
984263bc 84extern int __mb_cur_max;
0d5acd74 85extern int ___mb_cur_max(void);
b345f56c 86#define MB_CUR_MAX ((size_t)___mb_cur_max())
984263bc 87
5baeefc7 88void abort(void) __dead2;
5d0641a4 89/* void abort2(const char *, int, void **) __dead2; */
4d42eed2 90#if !defined(_KERNEL_VIRTUAL)
5baeefc7 91int abs(int) __pure2;
4d42eed2 92#endif
5baeefc7
JS
93int atexit(void (*)(void));
94double atof(const char *);
95int atoi(const char *);
96long atol(const char *);
97void *bsearch(const void *, const void *, size_t,
98 size_t, int (*)(const void *, const void *));
fc0e4e26 99void *calloc(size_t, size_t) __alloc_size2(1, 2) __malloclike __heedresult;
5baeefc7
JS
100div_t div(int, int) __pure2;
101void exit(int) __dead2;
102void free(void *);
103char *getenv(const char *);
4d42eed2 104#if !defined(_KERNEL_VIRTUAL)
5baeefc7 105long labs(long) __pure2;
4d42eed2 106#endif
5baeefc7 107ldiv_t ldiv(long, long) __pure2;
3d258b72 108void *malloc(size_t) __malloclike __heedresult __alloc_size(1);
5d0641a4
PA
109int mblen(const char *, size_t);
110size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
111int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
112void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
5baeefc7 113int rand(void);
3d258b72 114void *realloc(void *, size_t) __heedresult __alloc_size(2);
5baeefc7 115void srand(unsigned);
5d0641a4 116double strtod(const char * __restrict, char ** __restrict);
f202adf7 117float strtof(const char * __restrict, char ** __restrict);
5d0641a4
PA
118#if !defined(_KERNEL_VIRTUAL)
119long strtol(const char * __restrict, char ** __restrict, int);
984263bc 120#endif
f202adf7
PA
121long double
122 strtold(const char * __restrict, char ** __restrict);
44a09dd6 123#if !defined(_KERNEL_VIRTUAL)
5d0641a4
PA
124unsigned long
125 strtoul(const char * __restrict, char ** __restrict, int);
44a09dd6 126#endif
5d0641a4 127int system(const char *);
5baeefc7 128int wctomb(char *, wchar_t);
5d0641a4
PA
129size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
130
131/*
132 * Functions added in C99 which we make conditionally available in the
133 * BSD^C89 namespace if the compiler supports `long long'.
134 * The #if test is more complicated than it ought to be because
135 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
136 * is not supported in the compilation environment (which therefore means
137 * that it can't really be ISO C99).
138 *
139 * (The only other extension made by C99 in this header is _Exit().)
140 */
b345f56c 141#if __ISO_C_VISIBLE >= 1999 || defined(__cplusplus)
5d0641a4
PA
142#ifdef __LONG_LONG_SUPPORTED
143/* LONGLONG */
144typedef struct {
145 long long quot;
146 long long rem;
147} lldiv_t;
984263bc 148
5d0641a4
PA
149/* LONGLONG */
150long long
151 atoll(const char *);
152/* LONGLONG */
153long long
154 llabs(long long) __pure2;
155/* LONGLONG */
156lldiv_t lldiv(long long, long long) __pure2;
157/* LONGLONG */
158long long
159 strtoll(const char * __restrict, char ** __restrict, int);
160/* LONGLONG */
161unsigned long long
162 strtoull(const char * __restrict, char ** __restrict, int);
163#endif /* __LONG_LONG_SUPPORTED */
164
165void _Exit(int) __dead2;
166#endif /* __ISO_C_VISIBLE >= 1999 */
167
d8de7723 168/*
169 * C11 functions.
170 */
1e3ed379 171#if __ISO_C_VISIBLE >= 2011 || (defined(__cplusplus) && __cplusplus >= 201103L)
3d258b72 172void *aligned_alloc(size_t, size_t) __malloclike __heedresult
173 __alloc_align(1) __alloc_size(2);
174int at_quick_exit(void (*)(void)); /* extra extern case for __cplusplus? */
175void quick_exit(int) __dead2;
d8de7723 176#endif /* __ISO_C_VISIBLE >= 2011 */
177
5d0641a4 178/*
d6fa034f 179 * Extensions made by POSIX relative to C.
5d0641a4 180 */
d6fa034f 181#if __POSIX_VISIBLE >= 199506
5d0641a4 182int rand_r(unsigned *); /* (TSF) */
d6fa034f 183#endif
184#if __POSIX_VISIBLE >= 200112
3d258b72 185int posix_memalign(void **, size_t, size_t) __nonnull(1); /* (ADV) */
5baeefc7 186int setenv(const char *, const char *, int);
5d0641a4
PA
187int unsetenv(const char *);
188#endif
5baeefc7 189
3b63b459
SW
190#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
191int getsubopt(char **, char *const *, char **);
330f6769
SW
192#ifndef _MKDTEMP_DECLARED
193char *mkdtemp(char *);
194#define _MKDTEMP_DECLARED
195#endif
196#ifndef _MKSTEMP_DECLARED
197int mkstemp(char *);
198#define _MKSTEMP_DECLARED
199#endif
200#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
201
5d0641a4
PA
202/*
203 * The only changes to the XSI namespace in revision 6 were the deletion
204 * of the ttyslot() and valloc() functions, which we never declared
205 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which
206 * we also do not have, and mktemp(), are to be deleted.
207 */
208#if __XSI_VISIBLE
209/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */
210long a64l(const char *);
5baeefc7
JS
211double drand48(void);
212double erand48(unsigned short[3]);
f709978f 213#if 0
f85b95dd 214#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 700)
f709978f
SW
215char *ecvt(double, int, int * __restrict, int * __restrict); /* LEGACY */
216char *fcvt(double, int, int * __restrict, int * __restrict); /* LEGACY */
217char *gcvt(double, int, int * __restrict, int * __restrict); /* LEGACY */
218#endif
219#endif
c578a286 220int grantpt(int);
5d0641a4 221char *initstate(unsigned long /* XSI requires u_int */, char *, long);
5baeefc7 222long jrand48(unsigned short[3]);
5d0641a4 223char *l64a(long);
5baeefc7
JS
224void lcong48(unsigned short[7]);
225long lrand48(void);
f85b95dd
SW
226#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 700)
227#if !defined(_MKTEMP_DECLARED)
f709978f 228char *mktemp(char *); /* LEGACY */
330f6769
SW
229#define _MKTEMP_DECLARED
230#endif
f85b95dd 231#endif
5baeefc7
JS
232long mrand48(void);
233long nrand48(unsigned short[3]);
c578a286
AH
234int posix_openpt(int);
235char *ptsname(int);
5d0641a4
PA
236int putenv(char *);
237long random(void);
dcd5dd2e 238char *realpath(const char * __restrict, char * __restrict);
5d0641a4
PA
239unsigned short
240 *seed48(unsigned short[3]);
241int setkey(const char *);
242char *setstate(/* const */ char *);
5baeefc7 243void srand48(long);
5d0641a4 244void srandom(unsigned long);
c578a286 245int unlockpt(int);
5d0641a4 246#endif /* __XSI_VISIBLE */
5baeefc7 247
5d0641a4
PA
248#if __BSD_VISIBLE
249/* extern const char *_malloc_options;
250extern void (*_malloc_message)(const char *, const char *, const char *,
251 const char *); */
252
253/*
254 * The alloca() function can't be implemented in C, and on some
255 * platforms it can't be implemented at all as a callable function.
b6e3710e
SW
256 * The GNU C compiler provides a built-in alloca() which we can use.
257 * On platforms where alloca() is not in libc, programs which use it
258 * will fail to link when compiled with non-GNU compilers.
5d0641a4 259 */
c78f0d6a 260#if __GNUC__ >= 2
5d0641a4
PA
261#undef alloca /* some GNU bits try to get cute and define this on their own */
262#define alloca(sz) __builtin_alloca(sz)
5d0641a4
PA
263#endif
264
265__uint32_t
266 arc4random(void);
d82b6b65 267void arc4random_addrandom(__uint8_t *, size_t);
5d0641a4 268void arc4random_buf(void *, size_t);
5baeefc7 269void arc4random_stir(void);
5d0641a4
PA
270__uint32_t
271 arc4random_uniform(__uint32_t);
5baeefc7 272char *getbsize(int *, long *);
f736c3f8
SW
273
274/* getcap(3) functions */
6a7eb1f6 275char *cgetcap(char *, const char *, int);
5baeefc7 276int cgetclose(void);
6a7eb1f6 277int cgetent(char **, char **, const char *);
5baeefc7 278int cgetfirst(char **, char **);
6a7eb1f6 279int cgetmatch(const char *, const char *);
5baeefc7 280int cgetnext(char **, char **);
6a7eb1f6
PA
281int cgetnum(char *, const char *, long *);
282int cgetset(const char *);
283int cgetstr(char *, const char *, char **);
284int cgetustr(char *, const char *, char **);
5baeefc7 285
7307c476 286int clearenv(void);
5baeefc7 287int daemon(int, int);
24d00e84
JS
288char *devname(dev_t, mode_t);
289char *devname_r(dev_t, mode_t, char *, size_t);
f736c3f8
SW
290char *fdevname(int);
291int fdevname_r(int, char *, size_t);
78297c9b 292void freezero(void *, size_t);
3eaaad2c 293int getloadavg(double [], int);
b27f3669 294const char *
5d0641a4 295 getprogname(void);
5baeefc7 296
5baeefc7 297int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
5d0641a4 298int l64a_r(long, char *, int);
5baeefc7 299int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
5270936c
MD
300int mkostemp(char *, int);
301int mkostemps(char *, int, int);
5d0641a4
PA
302void qsort_r(void *, size_t, size_t, void *,
303 int (*)(void *, const void *, const void *));
5baeefc7
JS
304int radixsort(const unsigned char **, int, const unsigned char *,
305 unsigned int);
66932323 306void *reallocarray(void *, size_t, size_t) __heedresult __alloc_size2(2, 3);
64c3fdb4 307void *recallocarray(void *, size_t, size_t, size_t) __heedresult
308 __alloc_size2(3, 4);
3d258b72 309void *reallocf(void *, size_t) __heedresult __alloc_size(2);
5d0641a4 310int rpmatch(const char *);
5baeefc7 311void setprogname(const char *);
5d0641a4
PA
312int sradixsort(const unsigned char **, int, const unsigned char *,
313 unsigned int);
314void sranddev(void);
5baeefc7 315void srandomdev(void);
e6975a4e
SW
316long long
317 strsuftoll(const char *, const char *, long long, long long);
318long long
319 strsuftollx(const char *, const char *, long long, long long, char *,
320 size_t);
5d0641a4 321long long
f736c3f8 322 strtonum(const char *, long long, long long, const char **);
44a09dd6 323
5d0641a4
PA
324/* Deprecated interfaces. */
325#if !defined(_KERNEL_VIRTUAL)
326__int64_t
327 strtoq(const char *, char **, int);
328__uint64_t
329 strtouq(const char *, char **, int);
44a09dd6 330#endif
70e9d14e 331
5d0641a4
PA
332extern char *suboptarg; /* getsubopt(3) external variable */
333#endif /* __BSD_VISIBLE */
086b156c
SW
334
335#if __EXT1_VISIBLE
336/* K.3.6 */
337typedef void (*constraint_handler_t)(const char * __restrict,
338 void * __restrict, errno_t);
339/* K.3.6.1.1 */
340constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
341/* K.3.6.1.2 */
342_Noreturn void abort_handler_s(const char * __restrict, void * __restrict,
343 errno_t);
344/* K3.6.1.3 */
345void ignore_handler_s(const char * __restrict, void * __restrict, errno_t);
346#endif /* __EXT1_VISIBLE */
984263bc
MD
347__END_DECLS
348
349#endif /* !_STDLIB_H_ */