blob: b1ac1bf941ccd6e56ee058619073fad0db3f5155 [file] [log] [blame]
Juan Castillo9e751572014-11-17 17:27:41 +00001/*-
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.
13 * 3. Neither the name of the University nor the names of its contributors
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
30 * $FreeBSD$
31 */
32
33#ifndef _STDLIB_H_
34#define _STDLIB_H_
35
36#include <sys/cdefs.h>
37#include <sys/_null.h>
38#include <sys/_types.h>
39
40#if __BSD_VISIBLE
41#ifndef _RUNE_T_DECLARED
42typedef __rune_t rune_t;
43#define _RUNE_T_DECLARED
44#endif
45#endif
46
47#ifndef _SIZE_T_DECLARED
48typedef __size_t size_t;
49#define _SIZE_T_DECLARED
50#endif
51
52typedef struct {
53 int quot; /* quotient */
54 int rem; /* remainder */
55} div_t;
56
57typedef struct {
58 long quot;
59 long rem;
60} ldiv_t;
61
62#define EXIT_FAILURE 1
63#define EXIT_SUCCESS 0
64
65#define RAND_MAX 0x7ffffffd
66
67__BEGIN_DECLS
68#ifdef _XLOCALE_H_
69#include <xlocale/_stdlib.h>
70#endif
71extern int __mb_cur_max;
72extern int ___mb_cur_max(void);
73#define MB_CUR_MAX (___mb_cur_max())
74
75_Noreturn void abort(void);
76int abs(int) __pure2;
77int atexit(void (*)(void));
78double atof(const char *);
79int atoi(const char *);
80long atol(const char *);
81void *bsearch(const void *, const void *, size_t,
82 size_t, int (*)(const void *, const void *));
83void *calloc(size_t, size_t) __malloc_like;
84div_t div(int, int) __pure2;
85_Noreturn void exit(int);
86void free(void *);
87char *getenv(const char *);
88long labs(long) __pure2;
89ldiv_t ldiv(long, long) __pure2;
90void *malloc(size_t) __malloc_like;
91int mblen(const char *, size_t);
92void qsort(void *, size_t, size_t,
93 int (*)(const void *, const void *));
94int rand(void);
95void *realloc(void *, size_t);
96void srand(unsigned);
97double strtod(const char *__restrict, char **__restrict);
98float strtof(const char *__restrict, char **__restrict);
99long strtol(const char *__restrict, char **__restrict, int);
100long double
101 strtold(const char *__restrict, char **__restrict);
102unsigned long
103 strtoul(const char *__restrict, char **__restrict, int);
104int system(const char *);
105
106/*
107 * Functions added in C99 which we make conditionally available in the
108 * BSD^C89 namespace if the compiler supports `long long'.
109 * The #if test is more complicated than it ought to be because
110 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
111 * is not supported in the compilation environment (which therefore means
112 * that it can't really be ISO C99).
113 *
114 * (The only other extension made by C99 in thie header is _Exit().)
115 */
116#if __ISO_C_VISIBLE >= 1999
117#ifdef __LONG_LONG_SUPPORTED
118/* LONGLONG */
119typedef struct {
120 long long quot;
121 long long rem;
122} lldiv_t;
123
124/* LONGLONG */
125long long
126 atoll(const char *);
127/* LONGLONG */
128long long
129 llabs(long long) __pure2;
130/* LONGLONG */
131lldiv_t lldiv(long long, long long) __pure2;
132/* LONGLONG */
133long long
134 strtoll(const char *__restrict, char **__restrict, int);
135/* LONGLONG */
136unsigned long long
137 strtoull(const char *__restrict, char **__restrict, int);
138#endif /* __LONG_LONG_SUPPORTED */
139
140_Noreturn void _Exit(int);
141#endif /* __ISO_C_VISIBLE >= 1999 */
142
143/*
144 * If we're in a mode greater than C99, expose C11 functions.
145 */
146#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
147void *aligned_alloc(size_t, size_t) __malloc_like;
148int at_quick_exit(void (*)(void));
149_Noreturn void
150 quick_exit(int);
151#endif /* __ISO_C_VISIBLE >= 2011 */
152/*
153 * Extensions made by POSIX relative to C.
154 */
155#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE
156char *realpath(const char *__restrict, char *__restrict);
157#endif
158#if __POSIX_VISIBLE >= 199506
159int rand_r(unsigned *); /* (TSF) */
160#endif
161#if __POSIX_VISIBLE >= 200112
162int posix_memalign(void **, size_t, size_t); /* (ADV) */
163int setenv(const char *, const char *, int);
164int unsetenv(const char *);
165#endif
166
167#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
168int getsubopt(char **, char *const *, char **);
169#ifndef _MKDTEMP_DECLARED
170char *mkdtemp(char *);
171#define _MKDTEMP_DECLARED
172#endif
173#ifndef _MKSTEMP_DECLARED
174int mkstemp(char *);
175#define _MKSTEMP_DECLARED
176#endif
177#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
178
179/*
180 * The only changes to the XSI namespace in revision 6 were the deletion
181 * of the ttyslot() and valloc() functions, which FreeBSD never declared
182 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which
183 * FreeBSD also does not have, and mktemp(), are to be deleted.
184 */
185#if __XSI_VISIBLE
186/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */
187long a64l(const char *);
188double drand48(void);
189/* char *ecvt(double, int, int * __restrict, int * __restrict); */
190double erand48(unsigned short[3]);
191/* char *fcvt(double, int, int * __restrict, int * __restrict); */
192/* char *gcvt(double, int, int * __restrict, int * __restrict); */
193int grantpt(int);
194char *initstate(unsigned long /* XSI requires u_int */, char *, long);
195long jrand48(unsigned short[3]);
196char *l64a(long);
197void lcong48(unsigned short[7]);
198long lrand48(void);
199#if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600)
200char *mktemp(char *);
201#define _MKTEMP_DECLARED
202#endif
203long mrand48(void);
204long nrand48(unsigned short[3]);
205int posix_openpt(int);
206char *ptsname(int);
207int putenv(char *);
208long random(void);
209unsigned short
210 *seed48(unsigned short[3]);
211#ifndef _SETKEY_DECLARED
212int setkey(const char *);
213#define _SETKEY_DECLARED
214#endif
215char *setstate(/* const */ char *);
216void srand48(long);
217void srandom(unsigned long);
218int unlockpt(int);
219#endif /* __XSI_VISIBLE */
220
221#if __BSD_VISIBLE
222extern const char *malloc_conf;
223extern void (*malloc_message)(void *, const char *);
224
225/*
226 * The alloca() function can't be implemented in C, and on some
227 * platforms it can't be implemented at all as a callable function.
228 * The GNU C compiler provides a built-in alloca() which we can use;
229 * in all other cases, provide a prototype, mainly to pacify various
230 * incarnations of lint. On platforms where alloca() is not in libc,
231 * programs which use it will fail to link when compiled with non-GNU
232 * compilers.
233 */
234#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
235#undef alloca /* some GNU bits try to get cute and define this on their own */
236#define alloca(sz) __builtin_alloca(sz)
237#elif defined(lint)
238void *alloca(size_t);
239#endif
240
241void abort2(const char *, int, void **) __dead2;
242__uint32_t
243 arc4random(void);
244void arc4random_addrandom(unsigned char *, int);
245void arc4random_buf(void *, size_t);
246void arc4random_stir(void);
247__uint32_t
248 arc4random_uniform(__uint32_t);
249#ifdef __BLOCKS__
250int atexit_b(void (^)(void));
251void *bsearch_b(const void *, const void *, size_t,
252 size_t, int (^)(const void *, const void *));
253#endif
254char *getbsize(int *, long *);
255 /* getcap(3) functions */
256char *cgetcap(char *, const char *, int);
257int cgetclose(void);
258int cgetent(char **, char **, const char *);
259int cgetfirst(char **, char **);
260int cgetmatch(const char *, const char *);
261int cgetnext(char **, char **);
262int cgetnum(char *, const char *, long *);
263int cgetset(const char *);
264int cgetstr(char *, const char *, char **);
265int cgetustr(char *, const char *, char **);
266
267int daemon(int, int);
268char *devname(__dev_t, __mode_t);
269char *devname_r(__dev_t, __mode_t, char *, int);
270char *fdevname(int);
271char *fdevname_r(int, char *, int);
272int getloadavg(double [], int);
273const char *
274 getprogname(void);
275
276int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
277#ifdef __BLOCKS__
278int heapsort_b(void *, size_t, size_t, int (^)(const void *, const void *));
279void qsort_b(void *, size_t, size_t,
280 int (^)(const void *, const void *));
281#endif
282int l64a_r(long, char *, int);
283int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
284#ifdef __BLOCKS__
285int mergesort_b(void *, size_t, size_t, int (^)(const void *, const void *));
286#endif
287int mkostemp(char *, int);
288int mkostemps(char *, int, int);
289void qsort_r(void *, size_t, size_t, void *,
290 int (*)(void *, const void *, const void *));
291int radixsort(const unsigned char **, int, const unsigned char *,
292 unsigned);
293void *reallocf(void *, size_t);
294int rpmatch(const char *);
295void setprogname(const char *);
296int sradixsort(const unsigned char **, int, const unsigned char *,
297 unsigned);
298void sranddev(void);
299void srandomdev(void);
300long long
301 strtonum(const char *, long long, long long, const char **);
302
303/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
304__int64_t
305 strtoq(const char *, char **, int);
306__uint64_t
307 strtouq(const char *, char **, int);
308
309extern char *suboptarg; /* getsubopt(3) external variable */
310#endif /* __BSD_VISIBLE */
311__END_DECLS
312
313#endif /* !_STDLIB_H_ */