<stdlib.h>: Adjust the visibility of our C11 functions.
[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.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
5d0641a4 34 * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $
984263bc
MD
35 */
36
37#ifndef _STDLIB_H_
38#define _STDLIB_H_
39
40#include <sys/cdefs.h>
5d0641a4 41#include <sys/_null.h>
fa261b1d 42#include <sys/types.h>
984263bc 43
5d0641a4
PA
44#ifndef _SIZE_T_DECLARED
45typedef __size_t size_t;
46#define _SIZE_T_DECLARED
e2565a42 47#endif
984263bc 48
5d0641a4 49#ifndef __cplusplus
a81b3ef3 50#ifndef _WCHAR_T_DECLARED
5d0641a4
PA
51typedef __wchar_t wchar_t;
52#define _WCHAR_T_DECLARED
984263bc 53#endif
984263bc 54#endif
e2565a42 55
984263bc 56typedef struct {
5d0641a4
PA
57 int quot; /* quotient */
58 int rem; /* remainder */
984263bc
MD
59} div_t;
60
61typedef struct {
5d0641a4
PA
62 long quot;
63 long rem;
984263bc
MD
64} ldiv_t;
65
984263bc
MD
66#define EXIT_FAILURE 1
67#define EXIT_SUCCESS 0
68
69#define RAND_MAX 0x7fffffff
70
71extern int __mb_cur_max;
72#define MB_CUR_MAX __mb_cur_max
73
74__BEGIN_DECLS
5baeefc7 75void abort(void) __dead2;
5d0641a4 76/* void abort2(const char *, int, void **) __dead2; */
4d42eed2 77#if !defined(_KERNEL_VIRTUAL)
5baeefc7 78int abs(int) __pure2;
4d42eed2 79#endif
5baeefc7
JS
80int atexit(void (*)(void));
81double atof(const char *);
82int atoi(const char *);
83long atol(const char *);
84void *bsearch(const void *, const void *, size_t,
85 size_t, int (*)(const void *, const void *));
86void *calloc(size_t, size_t);
87div_t div(int, int) __pure2;
88void exit(int) __dead2;
89void free(void *);
90char *getenv(const char *);
4d42eed2 91#if !defined(_KERNEL_VIRTUAL)
5baeefc7 92long labs(long) __pure2;
4d42eed2 93#endif
5baeefc7
JS
94ldiv_t ldiv(long, long) __pure2;
95void *malloc(size_t);
11e45f67 96int posix_memalign(void **, size_t, size_t);
5d0641a4
PA
97int mblen(const char *, size_t);
98size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
99int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
100void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
5baeefc7
JS
101int rand(void);
102void *realloc(void *, size_t);
103void srand(unsigned);
5d0641a4 104double strtod(const char * __restrict, char ** __restrict);
f202adf7 105float strtof(const char * __restrict, char ** __restrict);
5d0641a4
PA
106#if !defined(_KERNEL_VIRTUAL)
107long strtol(const char * __restrict, char ** __restrict, int);
984263bc 108#endif
f202adf7
PA
109long double
110 strtold(const char * __restrict, char ** __restrict);
44a09dd6 111#if !defined(_KERNEL_VIRTUAL)
5d0641a4
PA
112unsigned long
113 strtoul(const char * __restrict, char ** __restrict, int);
44a09dd6 114#endif
5d0641a4 115int system(const char *);
5baeefc7 116int wctomb(char *, wchar_t);
5d0641a4
PA
117size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
118
119/*
120 * Functions added in C99 which we make conditionally available in the
121 * BSD^C89 namespace if the compiler supports `long long'.
122 * The #if test is more complicated than it ought to be because
123 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
124 * is not supported in the compilation environment (which therefore means
125 * that it can't really be ISO C99).
126 *
127 * (The only other extension made by C99 in this header is _Exit().)
128 */
129#if __ISO_C_VISIBLE >= 1999
130#ifdef __LONG_LONG_SUPPORTED
131/* LONGLONG */
132typedef struct {
133 long long quot;
134 long long rem;
135} lldiv_t;
984263bc 136
5d0641a4
PA
137/* LONGLONG */
138long long
139 atoll(const char *);
140/* LONGLONG */
141long long
142 llabs(long long) __pure2;
143/* LONGLONG */
144lldiv_t lldiv(long long, long long) __pure2;
145/* LONGLONG */
146long long
147 strtoll(const char * __restrict, char ** __restrict, int);
148/* LONGLONG */
149unsigned long long
150 strtoull(const char * __restrict, char ** __restrict, int);
151#endif /* __LONG_LONG_SUPPORTED */
152
153void _Exit(int) __dead2;
154#endif /* __ISO_C_VISIBLE >= 1999 */
155
156/*
157 * Extensions made by POSIX relative to C. We don't know yet which edition
158 * of POSIX made these extensions, so assume they've always been there until
159 * research can be done.
160 */
161#if __POSIX_VISIBLE /* >= ??? */
162/*int posix_memalign(void **, size_t, size_t); (ADV) */
163int rand_r(unsigned *); /* (TSF) */
5baeefc7 164int setenv(const char *, const char *, int);
5d0641a4
PA
165int unsetenv(const char *);
166#endif
5baeefc7 167
330f6769
SW
168#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
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
5d0641a4
PA
179/*
180 * The only changes to the XSI namespace in revision 6 were the deletion
181 * of the ttyslot() and valloc() functions, which we never declared
182 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which
183 * we also do 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 *);
5baeefc7 188double drand48(void);
5d0641a4 189/* char *ecvt(double, int, int * __restrict, int * __restrict); */
5baeefc7 190double erand48(unsigned short[3]);
5d0641a4
PA
191/* char *fcvt(double, int, int * __restrict, int * __restrict); */
192/* char *gcvt(double, int, int * __restrict, int * __restrict); */
193int getsubopt(char **, char *const *, char **);
c578a286 194int grantpt(int);
5d0641a4 195char *initstate(unsigned long /* XSI requires u_int */, char *, long);
5baeefc7 196long jrand48(unsigned short[3]);
5d0641a4 197char *l64a(long);
5baeefc7
JS
198void lcong48(unsigned short[7]);
199long lrand48(void);
330f6769
SW
200#if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600)
201char *mktemp(char *);
202#define _MKTEMP_DECLARED
203#endif
5baeefc7
JS
204long mrand48(void);
205long nrand48(unsigned short[3]);
c578a286
AH
206int posix_openpt(int);
207char *ptsname(int);
5d0641a4
PA
208int putenv(char *);
209long random(void);
dcd5dd2e 210char *realpath(const char * __restrict, char * __restrict);
5d0641a4
PA
211unsigned short
212 *seed48(unsigned short[3]);
213int setkey(const char *);
214char *setstate(/* const */ char *);
5baeefc7 215void srand48(long);
5d0641a4 216void srandom(unsigned long);
c578a286 217int unlockpt(int);
5d0641a4 218#endif /* __XSI_VISIBLE */
5baeefc7 219
5d0641a4
PA
220#if __BSD_VISIBLE
221/* extern const char *_malloc_options;
222extern void (*_malloc_message)(const char *, const char *, const char *,
223 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
241__uint32_t
242 arc4random(void);
d82b6b65 243void arc4random_addrandom(__uint8_t *, size_t);
5d0641a4 244void arc4random_buf(void *, size_t);
5baeefc7 245void arc4random_stir(void);
5d0641a4
PA
246__uint32_t
247 arc4random_uniform(__uint32_t);
5baeefc7 248char *getbsize(int *, long *);
f736c3f8
SW
249
250/* getcap(3) functions */
6a7eb1f6 251char *cgetcap(char *, const char *, int);
5baeefc7 252int cgetclose(void);
6a7eb1f6 253int cgetent(char **, char **, const char *);
5baeefc7 254int cgetfirst(char **, char **);
6a7eb1f6 255int cgetmatch(const char *, const char *);
5baeefc7 256int cgetnext(char **, char **);
6a7eb1f6
PA
257int cgetnum(char *, const char *, long *);
258int cgetset(const char *);
259int cgetstr(char *, const char *, char **);
260int cgetustr(char *, const char *, char **);
5baeefc7
JS
261
262int daemon(int, int);
24d00e84
JS
263char *devname(dev_t, mode_t);
264char *devname_r(dev_t, mode_t, char *, size_t);
f736c3f8
SW
265char *fdevname(int);
266int fdevname_r(int, char *, size_t);
3eaaad2c 267int getloadavg(double [], int);
b27f3669 268const char *
5d0641a4 269 getprogname(void);
5baeefc7 270
5baeefc7 271int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
5d0641a4 272int l64a_r(long, char *, int);
5baeefc7 273int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
5d0641a4
PA
274void qsort_r(void *, size_t, size_t, void *,
275 int (*)(void *, const void *, const void *));
5baeefc7
JS
276int radixsort(const unsigned char **, int, const unsigned char *,
277 unsigned int);
5baeefc7 278void *reallocf(void *, size_t);
5d0641a4 279int rpmatch(const char *);
5baeefc7 280void setprogname(const char *);
5d0641a4
PA
281int sradixsort(const unsigned char **, int, const unsigned char *,
282 unsigned int);
283void sranddev(void);
5baeefc7 284void srandomdev(void);
5d0641a4 285long long
f736c3f8 286 strtonum(const char *, long long, long long, const char **);
44a09dd6 287
5d0641a4
PA
288/* Deprecated interfaces. */
289#if !defined(_KERNEL_VIRTUAL)
290__int64_t
291 strtoq(const char *, char **, int);
292__uint64_t
293 strtouq(const char *, char **, int);
44a09dd6 294#endif
70e9d14e 295
5d0641a4
PA
296extern char *suboptarg; /* getsubopt(3) external variable */
297#endif /* __BSD_VISIBLE */
b8b8fcfe
SW
298
299/*
300 * C11 functions.
301 */
302#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L || __BSD_VISIBLE
303int at_quick_exit(void (*func)(void));
304void quick_exit(int) __dead2;
305void *aligned_alloc(size_t, size_t);
306#endif /* __ISO_C_VISIBLE >= 2011 */
307
984263bc
MD
308__END_DECLS
309
310#endif /* !_STDLIB_H_ */