stdlib.h revision 112163
1222900Snp/*-
2222900Snp * Copyright (c) 1990, 1993
3222900Snp *	The Regents of the University of California.  All rights reserved.
4222900Snp *
5222900Snp * Redistribution and use in source and binary forms, with or without
6222900Snp * modification, are permitted provided that the following conditions
7222900Snp * are met:
8222900Snp * 1. Redistributions of source code must retain the above copyright
9222900Snp *    notice, this list of conditions and the following disclaimer.
10222900Snp * 2. Redistributions in binary form must reproduce the above copyright
11222900Snp *    notice, this list of conditions and the following disclaimer in the
12222900Snp *    documentation and/or other materials provided with the distribution.
13222900Snp * 3. All advertising materials mentioning features or use of this software
14222900Snp *    must display the following acknowledgement:
15222900Snp *	This product includes software developed by the University of
16222900Snp *	California, Berkeley and its contributors.
17222900Snp * 4. Neither the name of the University nor the names of its contributors
18222900Snp *    may be used to endorse or promote products derived from this software
19222900Snp *    without specific prior written permission.
20222900Snp *
21222900Snp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22222900Snp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23222900Snp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24222900Snp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25222900Snp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26222900Snp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27222900Snp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28222900Snp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29222900Snp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30222900Snp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31287297Srodrigc * SUCH DAMAGE.
32222900Snp *
33228594Snp *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34222900Snp * $FreeBSD: head/include/stdlib.h 112163 2003-03-12 20:30:00Z das $
35228594Snp */
36287297Srodrigc
37287297Srodrigc#ifndef _STDLIB_H_
38222900Snp#define	_STDLIB_H_
39287297Srodrigc
40222900Snp#include <sys/cdefs.h>
41222900Snp#include <sys/_types.h>
42287297Srodrigc
43287297Srodrigc#if __BSD_VISIBLE
44287297Srodrigc#ifndef _RUNE_T_DECLARED
45287297Srodrigctypedef	__rune_t	rune_t;
46287297Srodrigc#define	_RUNE_T_DECLARED
47287297Srodrigc#endif
48287297Srodrigc#endif
49287297Srodrigc
50287297Srodrigc#ifndef _SIZE_T_DECLARED
51287297Srodrigctypedef	__size_t	size_t;
52287297Srodrigc#define	_SIZE_T_DECLARED
53222900Snp#endif
54222900Snp
55259048Snp#ifndef	__cplusplus
56222974Snp#ifndef _WCHAR_T_DECLARED
57222974Snptypedef	__wchar_t	wchar_t;
58222900Snp#define	_WCHAR_T_DECLARED
59253870Snp#endif
60222900Snp#endif
61222900Snp
62222900Snptypedef struct {
63222900Snp	int	quot;		/* quotient */
64222900Snp	int	rem;		/* remainder */
65222900Snp} div_t;
66222900Snp
67222900Snptypedef struct {
68222900Snp	long	quot;
69222900Snp	long	rem;
70222900Snp} ldiv_t;
71222900Snp
72222974Snp#ifndef NULL
73222974Snp#define	NULL	0
74222974Snp#endif
75222974Snp
76222974Snp#define	EXIT_FAILURE	1
77222974Snp#define	EXIT_SUCCESS	0
78222974Snp
79222974Snp#define	RAND_MAX	0x7fffffff
80222974Snp
81222900Snpextern int __mb_cur_max;
82296471Snp#define	MB_CUR_MAX	__mb_cur_max
83296471Snp
84222900Snp__BEGIN_DECLS
85222900Snpvoid	 abort(void) __dead2;
86222900Snpint	 abs(int) __pure2;
87222900Snpint	 atexit(void (*)(void));
88222900Snpdouble	 atof(const char *);
89222900Snpint	 atoi(const char *);
90222900Snplong	 atol(const char *);
91241416Snpvoid	*bsearch(const void *, const void *, size_t,
92222974Snp	    size_t, int (*)(const void *, const void *));
93222900Snpvoid	*calloc(size_t, size_t);
94222900Snpdiv_t	 div(int, int) __pure2;
95222900Snpvoid	 exit(int) __dead2;
96222900Snpvoid	 free(void *);
97241401Snpchar	*getenv(const char *);
98306823Snplong	 labs(long) __pure2;
99306823Snpldiv_t	 ldiv(long, long) __pure2;
100228594Snpvoid	*malloc(size_t);
101228594Snpint	 mblen(const char *, size_t);
102269106Snpsize_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
103222900Snpint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
104222900Snpvoid	 qsort(void *, size_t, size_t,
105222900Snp	    int (*)(const void *, const void *));
106259048Snpint	 rand(void);
107259048Snpvoid	*realloc(void *, size_t);
108222900Snpvoid	 srand(unsigned);
109228594Snpdouble	 strtod(const char * __restrict, char ** __restrict);
110259048Snpfloat	 strtof(const char * __restrict, char ** __restrict);
111253691Snplong	 strtol(const char * __restrict, char ** __restrict, int);
112253691Snplong double
113222900Snp	 strtold(const char * __restrict, char ** __restrict);
114222900Snpunsigned long
115222900Snp	 strtoul(const char * __restrict, char ** __restrict, int);
116222900Snpint	 system(const char *);
117222900Snpint	 wctomb(char *, wchar_t);
118222900Snpsize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
119222900Snp
120222900Snp/*
121222900Snp * Functions added in C99 which we make conditionally available in the
122222900Snp * BSD^C89 namespace if the compiler supports `long long'.
123222900Snp * The #if test is more complicated than it ought to be because
124222900Snp * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
125222900Snp * is not supported in the compilation environment (which therefore means
126222900Snp * that it can't really be ISO C99).
127222900Snp *
128222900Snp * (The only other extension made by C99 in thie header is _Exit().)
129222900Snp */
130222900Snp#if __ISO_C_VISIBLE >= 1999
131222900Snp#ifdef __LONG_LONG_SUPPORTED
132222900Snp/* LONGLONG */
133222900Snptypedef struct {
134222900Snp	long long quot;
135222900Snp	long long rem;
136222900Snp} lldiv_t;
137253870Snp
138222900Snp/* LONGLONG */
139222900Snplong long
140222900Snp	 atoll(const char *);
141222900Snp/* LONGLONG */
142222900Snplong long
143222900Snp	 llabs(long long) __pure2;
144222900Snp/* LONGLONG */
145222900Snplldiv_t	 lldiv(long long, long long) __pure2;
146222900Snp/* LONGLONG */
147222900Snplong long
148222900Snp	 strtoll(const char * __restrict, char ** __restrict, int);
149222900Snp/* LONGLONG */
150222900Snpunsigned long long
151222900Snp	 strtoull(const char * __restrict, char ** __restrict, int);
152222900Snp#endif /* __LONG_LONG_SUPPORTED */
153222900Snp
154222900Snpvoid	 _Exit(int) __dead2;
155222900Snp#endif /* __ISO_C_VISIBLE >= 1999 */
156222900Snp
157222900Snp/*
158222900Snp * Extensions made by POSIX relative to C.  We don't know yet which edition
159222900Snp * of POSIX made these extensions, so assume they've always been there until
160222900Snp * research can be done.
161222900Snp */
162222900Snp#if __POSIX_VISIBLE /* >= ??? */
163222900Snp/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
164222900Snpint	 rand_r(unsigned *);			/* (TSF) */
165222900Snpint	 setenv(const char *, const char *, int);
166222900Snpvoid	 unsetenv(const char *);
167222900Snp#endif
168222900Snp
169222900Snp/*
170222900Snp * The only changes to the XSI namespace in revision 6 were the deletion
171222900Snp * of the ttyslot() and valloc() functions, which FreeBSD never declared
172222900Snp * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
173222900Snp * FreeBSD also does not have, and mktemp(), are to be deleted.
174222900Snp */
175222900Snp#if __XSI_VISIBLE
176222900Snp/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
177222900Snp/* long	 a64l(const char *); */
178222900Snpdouble	 drand48(void);
179222900Snp/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
180222900Snpdouble	 erand48(unsigned short[3]);
181222900Snp/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
182222900Snp/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
183222900Snp#ifndef _GETSUBOPT_DECLARED
184222900Snpint	 getsubopt(char **, char *const *, char **);
185222900Snp#define	_GETSUBOPT_DECLARED
186222900Snp#endif
187222900Snpint	 grantpt(int);
188222900Snpchar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
189222900Snplong	 jrand48(unsigned short[3]);
190222900Snp/* char	*l64a(long); */
191222900Snpvoid	 lcong48(unsigned short[7]);
192222900Snplong	 lrand48(void);
193222900Snp#ifndef _MKSTEMP_DECLARED
194222900Snpint	 mkstemp(char *);
195222900Snp#define	_MKSTEMP_DECLARED
196222900Snp#endif
197222900Snp#ifndef _MKTEMP_DECLARED
198222900Snpchar	*mktemp(char *);
199222900Snp#define	_MKTEMP_DECLARED
200222900Snp#endif
201222900Snplong	 mrand48(void);
202222900Snplong	 nrand48(unsigned short[3]);
203222900Snpint	 posix_openpt(int);
204222900Snpchar	*ptsname(int);
205222900Snpint	 putenv(const char *);
206222900Snplong	 random(void);
207222900Snpchar	*realpath(const char *, char resolved_path[]);
208222900Snpunsigned short
209222900Snp	*seed48(unsigned short[3]);
210222900Snp#ifndef _SETKEY_DECLARED
211222900Snpint	 setkey(const char *);
212222900Snp#define	_SETKEY_DECLARED
213222900Snp#endif
214222900Snpchar	*setstate(/* const */ char *);
215222900Snpvoid	 srand48(long);
216222900Snpvoid	 srandom(unsigned long);
217222900Snpint	 unlockpt(int);
218222900Snp#endif /* __XSI_VISIBLE */
219222900Snp
220222900Snp#if __BSD_VISIBLE
221222900Snpextern const char *_malloc_options;
222222900Snpextern void (*_malloc_message)(const char *, const char *, const char *,
223222900Snp	    const char *);
224222900Snp
225222900Snpvoid	*alloca(size_t);		/* built-in for gcc */
226222900Snp__uint32_t
227222900Snp	 arc4random(void);
228222900Snpvoid	 arc4random_addrandom(unsigned char *dat, int datlen);
229222900Snpvoid	 arc4random_stir(void);
230222900Snpchar	*getbsize(int *, long *);
231222900Snp					/* getcap(3) functions */
232222900Snpchar	*cgetcap(char *, const char *, int);
233222900Snpint	 cgetclose(void);
234222900Snpint	 cgetent(char **, char **, const char *);
235222900Snpint	 cgetfirst(char **, char **);
236222900Snpint	 cgetmatch(const char *, const char *);
237222900Snpint	 cgetnext(char **, char **);
238222900Snpint	 cgetnum(char *, const char *, long *);
239222900Snpint	 cgetset(const char *);
240222900Snpint	 cgetstr(char *, const char *, char **);
241222900Snpint	 cgetustr(char *, const char *, char **);
242222900Snp
243222900Snpint	 daemon(int, int);
244222900Snpchar	*devname(int, int);
245222900Snpint	 getloadavg(double [], int);
246222900Snp__const char *
247222900Snp	 getprogname(void);
248222900Snp
249222900Snpint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
250222900Snpint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
251222900Snpvoid	 qsort_r(void *, size_t, size_t, void *,
252222900Snp	    int (*)(void *, const void *, const void *));
253222900Snpint	 radixsort(const unsigned char **, int, const unsigned char *,
254222900Snp	    unsigned);
255222900Snpvoid    *reallocf(void *, size_t);
256222900Snpvoid	 setprogname(const char *);
257222900Snpint	 sradixsort(const unsigned char **, int, const unsigned char *,
258222900Snp	    unsigned);
259222900Snpvoid	 sranddev(void);
260222900Snpvoid	 srandomdev(void);
261222900Snp
262222900Snp/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
263222900Snp__int64_t
264222900Snp	 strtoq(const char *, char **, int);
265222900Snp__uint64_t
266222900Snp	 strtouq(const char *, char **, int);
267222900Snp#endif /* __BSD_VISIBLE */
268222900Snp__END_DECLS
269222900Snp
270222900Snp#endif /* !_STDLIB_H_ */
271222900Snp