xref: /dragonfly/include/stdlib.h (revision 25a2db75)
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
34  * $FreeBSD: src/include/stdlib.h,v 1.67 2008/07/22 11:40:42 ache Exp $
35  */
36 
37 #ifndef _STDLIB_H_
38 #define	_STDLIB_H_
39 
40 #include <sys/cdefs.h>
41 #include <sys/_null.h>
42 #include <sys/types.h>
43 
44 #ifndef _SIZE_T_DECLARED
45 typedef	__size_t	size_t;
46 #define	_SIZE_T_DECLARED
47 #endif
48 
49 #ifndef	__cplusplus
50 #ifndef _WCHAR_T_DECLARED
51 typedef	__wchar_t	wchar_t;
52 #define	_WCHAR_T_DECLARED
53 #endif
54 #endif
55 
56 typedef struct {
57 	int	quot;		/* quotient */
58 	int	rem;		/* remainder */
59 } div_t;
60 
61 typedef struct {
62 	long	quot;
63 	long	rem;
64 } ldiv_t;
65 
66 #define	EXIT_FAILURE	1
67 #define	EXIT_SUCCESS	0
68 
69 #define	RAND_MAX	0x7fffffff
70 
71 extern int __mb_cur_max;
72 #define	MB_CUR_MAX	__mb_cur_max
73 
74 __BEGIN_DECLS
75 void	 abort(void) __dead2;
76 /* void	 abort2(const char *, int, void **) __dead2; */
77 #if !defined(_KERNEL_VIRTUAL)
78 int	 abs(int) __pure2;
79 #endif
80 int	 atexit(void (*)(void));
81 double	 atof(const char *);
82 int	 atoi(const char *);
83 long	 atol(const char *);
84 void	*bsearch(const void *, const void *, size_t,
85 		 size_t, int (*)(const void *, const void *));
86 void	*calloc(size_t, size_t);
87 div_t	 div(int, int) __pure2;
88 void	 exit(int) __dead2;
89 void	 free(void *);
90 char	*getenv(const char *);
91 #if !defined(_KERNEL_VIRTUAL)
92 long	 labs(long) __pure2;
93 #endif
94 ldiv_t	 ldiv(long, long) __pure2;
95 void	*malloc(size_t);
96 int	 posix_memalign(void **, size_t, size_t);
97 int	 mblen(const char *, size_t);
98 size_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
99 int	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
100 void	 qsort(void *, size_t, size_t, int (*)(const void *, const void *));
101 int	 rand(void);
102 void	*realloc(void *, size_t);
103 void	 srand(unsigned);
104 double	 strtod(const char * __restrict, char ** __restrict);
105 float	 strtof(const char * __restrict, char ** __restrict);
106 #if !defined(_KERNEL_VIRTUAL)
107 long	 strtol(const char * __restrict, char ** __restrict, int);
108 #endif
109 long double
110 	 strtold(const char * __restrict, char ** __restrict);
111 #if !defined(_KERNEL_VIRTUAL)
112 unsigned long
113 	 strtoul(const char * __restrict, char ** __restrict, int);
114 #endif
115 int	 system(const char *);
116 int	 wctomb(char *, wchar_t);
117 size_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 */
132 typedef struct {
133 	long long quot;
134 	long long rem;
135 } lldiv_t;
136 
137 /* LONGLONG */
138 long long
139 	 atoll(const char *);
140 /* LONGLONG */
141 long long
142 	 llabs(long long) __pure2;
143 /* LONGLONG */
144 lldiv_t	 lldiv(long long, long long) __pure2;
145 /* LONGLONG */
146 long long
147 	 strtoll(const char * __restrict, char ** __restrict, int);
148 /* LONGLONG */
149 unsigned long long
150 	 strtoull(const char * __restrict, char ** __restrict, int);
151 #endif /* __LONG_LONG_SUPPORTED */
152 
153 void	 _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) */
163 int	 rand_r(unsigned *);			/* (TSF) */
164 int	 setenv(const char *, const char *, int);
165 int	 unsetenv(const char *);
166 #endif
167 
168 #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
169 #ifndef _MKDTEMP_DECLARED
170 char	*mkdtemp(char *);
171 #define	_MKDTEMP_DECLARED
172 #endif
173 #ifndef _MKSTEMP_DECLARED
174 int	 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 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. */
187 long	 a64l(const char *);
188 double	 drand48(void);
189 /* char	*ecvt(double, int, int * __restrict, int * __restrict); */
190 double	 erand48(unsigned short[3]);
191 /* char	*fcvt(double, int, int * __restrict, int * __restrict); */
192 /* char	*gcvt(double, int, int * __restrict, int * __restrict); */
193 int	 getsubopt(char **, char *const *, char **);
194 int	 grantpt(int);
195 char	*initstate(unsigned long /* XSI requires u_int */, char *, long);
196 long	 jrand48(unsigned short[3]);
197 char	*l64a(long);
198 void	 lcong48(unsigned short[7]);
199 long	 lrand48(void);
200 #if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600)
201 char	*mktemp(char *);
202 #define	_MKTEMP_DECLARED
203 #endif
204 long	 mrand48(void);
205 long	 nrand48(unsigned short[3]);
206 int	 posix_openpt(int);
207 char	*ptsname(int);
208 int	 putenv(char *);
209 long	 random(void);
210 char	*realpath(const char * __restrict, char * __restrict);
211 unsigned short
212 	*seed48(unsigned short[3]);
213 int	 setkey(const char *);
214 char	*setstate(/* const */ char *);
215 void	 srand48(long);
216 void	 srandom(unsigned long);
217 int	 unlockpt(int);
218 #endif /* __XSI_VISIBLE */
219 
220 #if __BSD_VISIBLE
221 /* extern const char *_malloc_options;
222 extern 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)
238 void	*alloca(size_t);
239 #endif
240 
241 __uint32_t
242 	 arc4random(void);
243 void	 arc4random_addrandom(__uint8_t *, size_t);
244 void	 arc4random_buf(void *, size_t);
245 void	 arc4random_stir(void);
246 __uint32_t
247 	 arc4random_uniform(__uint32_t);
248 char	*getbsize(int *, long *);
249 
250 /* getcap(3) functions */
251 char	*cgetcap(char *, const char *, int);
252 int	 cgetclose(void);
253 int	 cgetent(char **, char **, const char *);
254 int	 cgetfirst(char **, char **);
255 int	 cgetmatch(const char *, const char *);
256 int	 cgetnext(char **, char **);
257 int	 cgetnum(char *, const char *, long *);
258 int	 cgetset(const char *);
259 int	 cgetstr(char *, const char *, char **);
260 int	 cgetustr(char *, const char *, char **);
261 
262 int	 daemon(int, int);
263 char	*devname(dev_t, mode_t);
264 char	*devname_r(dev_t, mode_t, char *, size_t);
265 char	*fdevname(int);
266 int	 fdevname_r(int, char *, size_t);
267 int	 getloadavg(double [], int);
268 const char *
269 	 getprogname(void);
270 
271 int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
272 int	 l64a_r(long, char *, int);
273 int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
274 void	 qsort_r(void *, size_t, size_t, void *,
275 		 int (*)(void *, const void *, const void *));
276 int	 radixsort(const unsigned char **, int, const unsigned char *,
277 		   unsigned int);
278 void    *reallocf(void *, size_t);
279 int	 rpmatch(const char *);
280 void	 setprogname(const char *);
281 int	 sradixsort(const unsigned char **, int, const unsigned char *,
282 		    unsigned int);
283 void	 sranddev(void);
284 void	 srandomdev(void);
285 long long
286 	 strtonum(const char *, long long, long long, const char **);
287 
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);
294 #endif
295 
296 extern char *suboptarg;			/* getsubopt(3) external variable */
297 #endif /* __BSD_VISIBLE */
298 
299 /*
300  * C11 functions.
301  */
302 #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L || __BSD_VISIBLE
303 int 	at_quick_exit(void (*func)(void));
304 void 	quick_exit(int) __dead2;
305 void	*aligned_alloc(size_t, size_t);
306 #endif /* __ISO_C_VISIBLE >= 2011 */
307 
308 __END_DECLS
309 
310 #endif /* !_STDLIB_H_ */
311