stdlib.h revision 171195
1139825Simp/*-
276588Sjoerg * Copyright (c) 1990, 1993
31019Sache *	The Regents of the University of California.  All rights reserved.
4877Sache *
51019Sache * Redistribution and use in source and binary forms, with or without
61019Sache * modification, are permitted provided that the following conditions
71019Sache * are met:
81019Sache * 1. Redistributions of source code must retain the above copyright
91019Sache *    notice, this list of conditions and the following disclaimer.
101019Sache * 2. Redistributions in binary form must reproduce the above copyright
111019Sache *    notice, this list of conditions and the following disclaimer in the
121019Sache *    documentation and/or other materials provided with the distribution.
13877Sache * 3. All advertising materials mentioning features or use of this software
142838Sdg *    must display the following acknowledgement:
152838Sdg *	This product includes software developed by the University of
162838Sdg *	California, Berkeley and its contributors.
172838Sdg * 4. Neither the name of the University nor the names of its contributors
182838Sdg *    may be used to endorse or promote products derived from this software
192838Sdg *    without specific prior written permission.
202838Sdg *
212838Sdg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222838Sdg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
232838Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242838Sdg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
252838Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261817Sdg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2750477Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28877Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29877Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3018444Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3118444Sbde * SUCH DAMAGE.
32877Sache *
3355205Speter *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34877Sache * $FreeBSD: head/include/stdlib.h 171195 2007-07-04 00:00:41Z scf $
3518444Sbde */
3618444Sbde
37877Sache#ifndef _STDLIB_H_
38877Sache#define	_STDLIB_H_
39877Sache
40877Sache#include <sys/cdefs.h>
41877Sache#include <sys/_null.h>
42877Sache#include <sys/_types.h>
43877Sache
44877Sache#if __BSD_VISIBLE
4587992Sjoerg#ifndef _RUNE_T_DECLARED
46877Sachetypedef	__rune_t	rune_t;
47134081Sphk#define	_RUNE_T_DECLARED
48134081Sphk#endif
49134081Sphk#endif
50134081Sphk
51134081Sphk#ifndef _SIZE_T_DECLARED
52134081Sphktypedef	__size_t	size_t;
53134081Sphk#define	_SIZE_T_DECLARED
54134081Sphk#endif
55134081Sphk
56134081Sphk#ifndef	__cplusplus
57134081Sphk#ifndef _WCHAR_T_DECLARED
58134081Sphktypedef	__wchar_t	wchar_t;
59877Sache#define	_WCHAR_T_DECLARED
60134081Sphk#endif
61134081Sphk#endif
62134081Sphk
63877Sachetypedef struct {
64134081Sphk	int	quot;		/* quotient */
65134081Sphk	int	rem;		/* remainder */
66134081Sphk} div_t;
67134081Sphk
68134081Sphktypedef struct {
69877Sache	long	quot;
70877Sache	long	rem;
71877Sache} ldiv_t;
72877Sache
73134081Sphk#define	EXIT_FAILURE	1
74134081Sphk#define	EXIT_SUCCESS	0
75134081Sphk
76134081Sphk#define	RAND_MAX	0x7fffffff
77877Sache
78134081Sphkextern int __mb_cur_max;
79134081Sphk#define	MB_CUR_MAX	__mb_cur_max
80134081Sphk
81134081Sphk__BEGIN_DECLS
82877Sachevoid	 abort(void) __dead2;
83877Sachevoid	 abort2(const char *, int, void **) __dead2;
84877Sacheint	 abs(int) __pure2;
85877Sacheint	 atexit(void (*)(void));
86877Sachedouble	 atof(const char *);
87877Sacheint	 atoi(const char *);
8887992Sjoerglong	 atol(const char *);
89877Sachevoid	*bsearch(const void *, const void *, size_t,
90877Sache	    size_t, int (*)(const void *, const void *));
91877Sachevoid	*calloc(size_t, size_t);
92891Sachediv_t	 div(int, int) __pure2;
93891Sachevoid	 exit(int) __dead2;
9487992Sjoergvoid	 free(void *);
9587992Sjoergchar	*getenv(const char *);
9687992Sjoerglong	 labs(long) __pure2;
9787992Sjoergldiv_t	 ldiv(long, long) __pure2;
9887992Sjoergvoid	*malloc(size_t);
99134081Sphkint	 mblen(const char *, size_t);
100877Sachesize_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
101877Sacheint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
10276588Sjoergvoid	 qsort(void *, size_t, size_t,
10376588Sjoerg	    int (*)(const void *, const void *));
10476588Sjoergint	 rand(void);
10576588Sjoergvoid	*realloc(void *, size_t);
10678856Sjoergvoid	 srand(unsigned);
10778856Sjoergdouble	 strtod(const char * __restrict, char ** __restrict);
10878856Sjoergfloat	 strtof(const char * __restrict, char ** __restrict);
10978856Sjoerglong	 strtol(const char * __restrict, char ** __restrict, int);
11078856Sjoerglong double
11178856Sjoerg	 strtold(const char * __restrict, char ** __restrict);
11278856Sjoergunsigned long
11378856Sjoerg	 strtoul(const char * __restrict, char ** __restrict, int);
11478856Sjoergint	 system(const char *);
11578856Sjoergint	 wctomb(char *, wchar_t);
11678856Sjoergsize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
11787992Sjoerg
11887992Sjoerg/*
11987992Sjoerg * Functions added in C99 which we make conditionally available in the
12087992Sjoerg * BSD^C89 namespace if the compiler supports `long long'.
12187992Sjoerg * The #if test is more complicated than it ought to be because
12287992Sjoerg * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
12387992Sjoerg * is not supported in the compilation environment (which therefore means
12487992Sjoerg * that it can't really be ISO C99).
12587992Sjoerg *
12687992Sjoerg * (The only other extension made by C99 in thie header is _Exit().)
127877Sache */
128877Sache#if __ISO_C_VISIBLE >= 1999
1292838Sdg#ifdef __LONG_LONG_SUPPORTED
130877Sache/* LONGLONG */
1312838Sdgtypedef struct {
1322838Sdg	long long quot;
133134207Snyan	long long rem;
134134207Snyan} lldiv_t;
135134207Snyan
136134207Snyan/* LONGLONG */
1372838Sdglong long
13876588Sjoerg	 atoll(const char *);
1392838Sdg/* LONGLONG */
14078856Sjoerglong long
14178856Sjoerg	 llabs(long long) __pure2;
1423095Sjoerg/* LONGLONG */
14376588Sjoerglldiv_t	 lldiv(long long, long long) __pure2;
14476588Sjoerg/* LONGLONG */
14576588Sjoerglong long
14687992Sjoerg	 strtoll(const char * __restrict, char ** __restrict, int);
14776588Sjoerg/* LONGLONG */
14887992Sjoergunsigned long long
14987992Sjoerg	 strtoull(const char * __restrict, char ** __restrict, int);
15076588Sjoerg#endif /* __LONG_LONG_SUPPORTED */
15176588Sjoerg
15276588Sjoergvoid	 _Exit(int) __dead2;
15376588Sjoerg#endif /* __ISO_C_VISIBLE >= 1999 */
15476588Sjoerg
155134081Sphk/*
15687992Sjoerg * Extensions made by POSIX relative to C.  We don't know yet which edition
15787992Sjoerg * of POSIX made these extensions, so assume they've always been there until
158134081Sphk * research can be done.
15976588Sjoerg */
16076588Sjoerg#if __POSIX_VISIBLE /* >= ??? */
16187992Sjoergint	 posix_memalign(void **, size_t, size_t); /* (ADV) */
16287992Sjoergint	 rand_r(unsigned *);			/* (TSF) */
16387992Sjoergint	 setenv(const char *, const char *, int);
16487992Sjoergint	 unsetenv(const char *);
16587992Sjoerg#endif
1663095Sjoerg
1673095Sjoerg/*
1683095Sjoerg * The only changes to the XSI namespace in revision 6 were the deletion
1693095Sjoerg * of the ttyslot() and valloc() functions, which FreeBSD never declared
17087992Sjoerg * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
1713095Sjoerg * FreeBSD also does not have, and mktemp(), are to be deleted.
172134081Sphk */
173134081Sphk#if __XSI_VISIBLE
174134081Sphk/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
175134081Sphklong	 a64l(const char *);
176134081Sphkdouble	 drand48(void);
177134081Sphk/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
178134081Sphkdouble	 erand48(unsigned short[3]);
179134081Sphk/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
180134081Sphk/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
181134081Sphkint	 getsubopt(char **, char *const *, char **);
182134081Sphkint	 grantpt(int);
183137459Snyanchar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
184137459Snyanlong	 jrand48(unsigned short[3]);
185137459Snyanchar	*l64a(long);
186137459Snyanvoid	 lcong48(unsigned short[7]);
187137459Snyanlong	 lrand48(void);
188137459Snyan#ifndef _MKSTEMP_DECLARED
189137459Snyanint	 mkstemp(char *);
190137459Snyan#define	_MKSTEMP_DECLARED
191137459Snyan#endif
192137459Snyan#ifndef _MKTEMP_DECLARED
193137459Snyanchar	*mktemp(char *);
194137459Snyan#define	_MKTEMP_DECLARED
195137459Snyan#endif
196134081Sphklong	 mrand48(void);
197134081Sphklong	 nrand48(unsigned short[3]);
198134081Sphkint	 posix_openpt(int);
199134081Sphkchar	*ptsname(int);
200134081Sphkint	 putenv(char *);
201134081Sphklong	 random(void);
202134081Sphkchar	*realpath(const char *, char resolved_path[]);
203134081Sphkunsigned short
204134081Sphk	*seed48(unsigned short[3]);
205134081Sphk#ifndef _SETKEY_DECLARED
206134081Sphkint	 setkey(const char *);
207134081Sphk#define	_SETKEY_DECLARED
208134081Sphk#endif
209134081Sphkchar	*setstate(/* const */ char *);
210134081Sphkvoid	 srand48(long);
211134081Sphkvoid	 srandom(unsigned long);
212134081Sphkint	 unlockpt(int);
213134081Sphk#endif /* __XSI_VISIBLE */
214137459Snyan
215134081Sphk#if __BSD_VISIBLE
21618444Sbdeextern const char *_malloc_options;
217extern void (*_malloc_message)(const char *, const char *, const char *,
218	    const char *);
219
220/*
221 * The alloca() function can't be implemented in C, and on some
222 * platforms it can't be implemented at all as a callable function.
223 * The GNU C compiler provides a built-in alloca() which we can use;
224 * in all other cases, provide a prototype, mainly to pacify various
225 * incarnations of lint.  On platforms where alloca() is not in libc,
226 * programs which use it will fail to link when compiled with non-GNU
227 * compilers.
228 */
229#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
230#undef  alloca	/* some GNU bits try to get cute and define this on their own */
231#define alloca(sz) __builtin_alloca(sz)
232#elif defined(lint)
233void	*alloca(size_t);
234#endif
235
236__uint32_t
237	 arc4random(void);
238void	 arc4random_addrandom(unsigned char *dat, int datlen);
239void	 arc4random_stir(void);
240char	*getbsize(int *, long *);
241					/* getcap(3) functions */
242char	*cgetcap(char *, const char *, int);
243int	 cgetclose(void);
244int	 cgetent(char **, char **, const char *);
245int	 cgetfirst(char **, char **);
246int	 cgetmatch(const char *, const char *);
247int	 cgetnext(char **, char **);
248int	 cgetnum(char *, const char *, long *);
249int	 cgetset(const char *);
250int	 cgetstr(char *, const char *, char **);
251int	 cgetustr(char *, const char *, char **);
252
253int	 daemon(int, int);
254char	*devname(__dev_t, __mode_t);
255char 	*devname_r(__dev_t, __mode_t, char *, int);
256int	 getloadavg(double [], int);
257__const char *
258	 getprogname(void);
259
260int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
261int	 l64a_r(long, char *, int);
262int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
263void	 qsort_r(void *, size_t, size_t, void *,
264	    int (*)(void *, const void *, const void *));
265int	 radixsort(const unsigned char **, int, const unsigned char *,
266	    unsigned);
267void    *reallocf(void *, size_t);
268int	 rpmatch(const char *);
269void	 setprogname(const char *);
270int	 sradixsort(const unsigned char **, int, const unsigned char *,
271	    unsigned);
272void	 sranddev(void);
273void	 srandomdev(void);
274long long
275	strtonum(const char *, long long, long long, const char **);
276
277/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
278__int64_t
279	 strtoq(const char *, char **, int);
280__uint64_t
281	 strtouq(const char *, char **, int);
282
283extern char *suboptarg;			/* getsubopt(3) external variable */
284#endif /* __BSD_VISIBLE */
285__END_DECLS
286
287#endif /* !_STDLIB_H_ */
288