stdlib.h revision 126136
1142425Snectar/*-
2160814Ssimon * Copyright (c) 1990, 1993
3142425Snectar *	The Regents of the University of California.  All rights reserved.
4142425Snectar *
5142425Snectar * Redistribution and use in source and binary forms, with or without
6142425Snectar * modification, are permitted provided that the following conditions
7142425Snectar * are met:
8142425Snectar * 1. Redistributions of source code must retain the above copyright
9142425Snectar *    notice, this list of conditions and the following disclaimer.
10142425Snectar * 2. Redistributions in binary form must reproduce the above copyright
11142425Snectar *    notice, this list of conditions and the following disclaimer in the
12142425Snectar *    documentation and/or other materials provided with the distribution.
13142425Snectar * 3. All advertising materials mentioning features or use of this software
14142425Snectar *    must display the following acknowledgement:
15142425Snectar *	This product includes software developed by the University of
16142425Snectar *	California, Berkeley and its contributors.
17142425Snectar * 4. Neither the name of the University nor the names of its contributors
18142425Snectar *    may be used to endorse or promote products derived from this software
19142425Snectar *    without specific prior written permission.
20238405Sjkim *
21160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22238405Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24142425Snectar * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25142425Snectar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26142425Snectar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27142425Snectar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28142425Snectar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29142425Snectar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30142425Snectar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31142425Snectar * SUCH DAMAGE.
32142425Snectar *
33142425Snectar *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34142425Snectar * $FreeBSD: head/include/stdlib.h 126136 2004-02-23 03:16:59Z ache $
35142425Snectar */
36142425Snectar
37142425Snectar#ifndef _STDLIB_H_
38238405Sjkim#define	_STDLIB_H_
39142425Snectar
40142425Snectar#include <sys/cdefs.h>
41142425Snectar#include <sys/_null.h>
42142425Snectar#include <sys/_types.h>
43142425Snectar
44142425Snectar#if __BSD_VISIBLE
45142425Snectar#ifndef _RUNE_T_DECLARED
46142425Snectartypedef	__rune_t	rune_t;
47142425Snectar#define	_RUNE_T_DECLARED
48142425Snectar#endif
49142425Snectar#endif
50142425Snectar
51160814Ssimon#ifndef _SIZE_T_DECLARED
52160814Ssimontypedef	__size_t	size_t;
53142425Snectar#define	_SIZE_T_DECLARED
54142425Snectar#endif
55142425Snectar
56142425Snectar#ifndef	__cplusplus
57142425Snectar#ifndef _WCHAR_T_DECLARED
58142425Snectartypedef	__wchar_t	wchar_t;
59142425Snectar#define	_WCHAR_T_DECLARED
60142425Snectar#endif
61142425Snectar#endif
62142425Snectar
63142425Snectartypedef struct {
64142425Snectar	int	quot;		/* quotient */
65142425Snectar	int	rem;		/* remainder */
66142425Snectar} div_t;
67160814Ssimon
68142425Snectartypedef struct {
69142425Snectar	long	quot;
70142425Snectar	long	rem;
71142425Snectar} ldiv_t;
72142425Snectar
73142425Snectar#define	EXIT_FAILURE	1
74142425Snectar#define	EXIT_SUCCESS	0
75142425Snectar
76142425Snectar#define	RAND_MAX	0x7fffffff
77142425Snectar
78142425Snectarextern int __mb_cur_max;
79160814Ssimon#define	MB_CUR_MAX	__mb_cur_max
80160814Ssimon
81142425Snectar__BEGIN_DECLS
82238405Sjkimvoid	 abort(void) __dead2;
83238405Sjkimint	 abs(int) __pure2;
84238405Sjkimint	 atexit(void (*)(void));
85238405Sjkimdouble	 atof(const char *);
86238405Sjkimint	 atoi(const char *);
87238405Sjkimlong	 atol(const char *);
88238405Sjkimvoid	*bsearch(const void *, const void *, size_t,
89142425Snectar	    size_t, int (*)(const void *, const void *));
90142425Snectarvoid	*calloc(size_t, size_t);
91142425Snectardiv_t	 div(int, int) __pure2;
92142425Snectarvoid	 exit(int) __dead2;
93142425Snectarvoid	 free(void *);
94142425Snectarchar	*getenv(const char *);
95142425Snectarlong	 labs(long) __pure2;
96142425Snectarldiv_t	 ldiv(long, long) __pure2;
97142425Snectarvoid	*malloc(size_t);
98142425Snectarint	 mblen(const char *, size_t);
99142425Snectarsize_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
100194206Ssimonint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
101194206Ssimonvoid	 qsort(void *, size_t, size_t,
102238405Sjkim	    int (*)(const void *, const void *));
103194206Ssimonint	 rand(void);
104194206Ssimonvoid	*realloc(void *, size_t);
105194206Ssimonvoid	 srand(unsigned);
106194206Ssimondouble	 strtod(const char * __restrict, char ** __restrict);
107194206Ssimonfloat	 strtof(const char * __restrict, char ** __restrict);
108142425Snectarlong	 strtol(const char * __restrict, char ** __restrict, int);
109194206Ssimonlong double
110194206Ssimon	 strtold(const char * __restrict, char ** __restrict);
111160814Ssimonunsigned long
112194206Ssimon	 strtoul(const char * __restrict, char ** __restrict, int);
113238405Sjkimint	 system(const char *);
114160814Ssimonint	 wctomb(char *, wchar_t);
115160814Ssimonsize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
116160814Ssimon
117160814Ssimon/*
118238405Sjkim * Functions added in C99 which we make conditionally available in the
119238405Sjkim * BSD^C89 namespace if the compiler supports `long long'.
120238405Sjkim * The #if test is more complicated than it ought to be because
121238405Sjkim * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
122238405Sjkim * is not supported in the compilation environment (which therefore means
123238405Sjkim * that it can't really be ISO C99).
124160814Ssimon *
125160814Ssimon * (The only other extension made by C99 in thie header is _Exit().)
126160814Ssimon */
127142425Snectar#if __ISO_C_VISIBLE >= 1999
128238405Sjkim#ifdef __LONG_LONG_SUPPORTED
129238405Sjkim/* LONGLONG */
130142425Snectartypedef struct {
131160814Ssimon	long long quot;
132160814Ssimon	long long rem;
133160814Ssimon} lldiv_t;
134160814Ssimon
135160814Ssimon/* LONGLONG */
136160814Ssimonlong long
137160814Ssimon	 atoll(const char *);
138142425Snectar/* LONGLONG */
139238405Sjkimlong long
140238405Sjkim	 llabs(long long) __pure2;
141142425Snectar/* LONGLONG */
142142425Snectarlldiv_t	 lldiv(long long, long long) __pure2;
143160814Ssimon/* LONGLONG */
144160814Ssimonlong long
145160814Ssimon	 strtoll(const char * __restrict, char ** __restrict, int);
146160814Ssimon/* LONGLONG */
147160814Ssimonunsigned long long
148160814Ssimon	 strtoull(const char * __restrict, char ** __restrict, int);
149160814Ssimon#endif /* __LONG_LONG_SUPPORTED */
150142425Snectar
151238405Sjkimvoid	 _Exit(int) __dead2;
152238405Sjkim#endif /* __ISO_C_VISIBLE >= 1999 */
153142425Snectar
154160814Ssimon/*
155160814Ssimon * Extensions made by POSIX relative to C.  We don't know yet which edition
156160814Ssimon * of POSIX made these extensions, so assume they've always been there until
157160814Ssimon * research can be done.
158142425Snectar */
159142425Snectar#if __POSIX_VISIBLE /* >= ??? */
160142425Snectar/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
161142425Snectarint	 rand_r(unsigned *);			/* (TSF) */
162142425Snectarint	 setenv(const char *, const char *, int);
163142425Snectarvoid	 unsetenv(const char *);
164142425Snectar#endif
165
166/*
167 * The only changes to the XSI namespace in revision 6 were the deletion
168 * of the ttyslot() and valloc() functions, which FreeBSD never declared
169 * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
170 * FreeBSD also does not have, and mktemp(), are to be deleted.
171 */
172#if __XSI_VISIBLE
173/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
174/* long	 a64l(const char *); */
175double	 drand48(void);
176/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
177double	 erand48(unsigned short[3]);
178/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
179/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
180int	 getsubopt(char **, char *const *, char **);
181int	 grantpt(int);
182char	*initstate(unsigned long /* XSI requires u_int */, char *, long);
183long	 jrand48(unsigned short[3]);
184/* char	*l64a(long); */
185void	 lcong48(unsigned short[7]);
186long	 lrand48(void);
187#ifndef _MKSTEMP_DECLARED
188int	 mkstemp(char *);
189#define	_MKSTEMP_DECLARED
190#endif
191#ifndef _MKTEMP_DECLARED
192char	*mktemp(char *);
193#define	_MKTEMP_DECLARED
194#endif
195long	 mrand48(void);
196long	 nrand48(unsigned short[3]);
197int	 posix_openpt(int);
198char	*ptsname(int);
199int	 putenv(const char *);
200long	 random(void);
201char	*realpath(const char *, char resolved_path[]);
202unsigned short
203	*seed48(unsigned short[3]);
204#ifndef _SETKEY_DECLARED
205int	 setkey(const char *);
206#define	_SETKEY_DECLARED
207#endif
208char	*setstate(/* const */ char *);
209void	 srand48(long);
210void	 srandom(unsigned long);
211int	 unlockpt(int);
212#endif /* __XSI_VISIBLE */
213
214#if __BSD_VISIBLE
215extern const char *_malloc_options;
216extern void (*_malloc_message)(const char *, const char *, const char *,
217	    const char *);
218
219/*
220 * The alloca() function can't be implemented in C, and on some
221 * platforms it can't be implemented at all as a callable function.
222 * The GNU C compiler provides a built-in alloca() which we can use;
223 * in all other cases, provide a prototype, mainly to pacify various
224 * incarnations of lint.  On platforms where alloca() is not in libc,
225 * programs which use it will fail to link when compiled with non-GNU
226 * compilers.
227 */
228#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
229#undef  alloca	/* some GNU bits try to get cute and define this on their own */
230#define alloca(sz) __builtin_alloca(sz)
231#elif defined(lint)
232void	*alloca(size_t);
233#endif
234
235__uint32_t
236	 arc4random(void);
237void	 arc4random_addrandom(unsigned char *dat, int datlen);
238void	 arc4random_stir(void);
239char	*getbsize(int *, long *);
240					/* getcap(3) functions */
241char	*cgetcap(char *, const char *, int);
242int	 cgetclose(void);
243int	 cgetent(char **, char **, const char *);
244int	 cgetfirst(char **, char **);
245int	 cgetmatch(const char *, const char *);
246int	 cgetnext(char **, char **);
247int	 cgetnum(char *, const char *, long *);
248int	 cgetset(const char *);
249int	 cgetstr(char *, const char *, char **);
250int	 cgetustr(char *, const char *, char **);
251
252int	 daemon(int, int);
253char	*devname(int, int);
254char 	*devname_r(int, int, char *, int);
255int	 getloadavg(double [], int);
256__const char *
257	 getprogname(void);
258
259int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
260int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
261void	 qsort_r(void *, size_t, size_t, void *,
262	    int (*)(void *, const void *, const void *));
263int	 radixsort(const unsigned char **, int, const unsigned char *,
264	    unsigned);
265void    *reallocf(void *, size_t);
266void	 setprogname(const char *);
267int	 sradixsort(const unsigned char **, int, const unsigned char *,
268	    unsigned);
269void	 sranddev(void);
270void	 srandomdev(void);
271
272/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
273__int64_t
274	 strtoq(const char *, char **, int);
275__uint64_t
276	 strtouq(const char *, char **, int);
277
278extern char *suboptarg;			/* getsubopt(3) external variable */
279#endif /* __BSD_VISIBLE */
280__END_DECLS
281
282#endif /* !_STDLIB_H_ */
283