stdlib.h revision 189820
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1990, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
3323657Speter *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
3455031Sbde * $FreeBSD: head/include/stdlib.h 189820 2009-03-14 19:13:30Z das $
351539Srgrimes */
361539Srgrimes
371539Srgrimes#ifndef _STDLIB_H_
387865Sbde#define	_STDLIB_H_
391539Srgrimes
4033861Sbde#include <sys/cdefs.h>
41123257Smarcel#include <sys/_null.h>
42102227Smike#include <sys/_types.h>
4333861Sbde
44103728Swollman#if __BSD_VISIBLE
45102227Smike#ifndef _RUNE_T_DECLARED
46102227Smiketypedef	__rune_t	rune_t;
47102227Smike#define	_RUNE_T_DECLARED
4815483Sbde#endif
4915483Sbde#endif
5015483Sbde
51102227Smike#ifndef _SIZE_T_DECLARED
52102227Smiketypedef	__size_t	size_t;
53102227Smike#define	_SIZE_T_DECLARED
541539Srgrimes#endif
551539Srgrimes
5699640Sobrien#ifndef	__cplusplus
57102227Smike#ifndef _WCHAR_T_DECLARED
58102227Smiketypedef	__wchar_t	wchar_t;
59102227Smike#define	_WCHAR_T_DECLARED
601539Srgrimes#endif
6199640Sobrien#endif
621539Srgrimes
631539Srgrimestypedef struct {
64103766Sbde	int	quot;		/* quotient */
65103766Sbde	int	rem;		/* remainder */
661539Srgrimes} div_t;
671539Srgrimes
681539Srgrimestypedef struct {
69103766Sbde	long	quot;
70103766Sbde	long	rem;
711539Srgrimes} ldiv_t;
721539Srgrimes
731539Srgrimes#define	EXIT_FAILURE	1
741539Srgrimes#define	EXIT_SUCCESS	0
751539Srgrimes
761539Srgrimes#define	RAND_MAX	0x7fffffff
771539Srgrimes
781539Srgrimesextern int __mb_cur_max;
791539Srgrimes#define	MB_CUR_MAX	__mb_cur_max
801539Srgrimes
811539Srgrimes__BEGIN_DECLS
8293032Simpvoid	 abort(void) __dead2;
8393032Simpint	 abs(int) __pure2;
8493032Simpint	 atexit(void (*)(void));
8593032Simpdouble	 atof(const char *);
8693032Simpint	 atoi(const char *);
8793032Simplong	 atol(const char *);
8893032Simpvoid	*bsearch(const void *, const void *, size_t,
8993032Simp	    size_t, int (*)(const void *, const void *));
90187961Sdasvoid	*calloc(size_t, size_t) __malloc_like;
9193032Simpdiv_t	 div(int, int) __pure2;
9293032Simpvoid	 exit(int) __dead2;
9393032Simpvoid	 free(void *);
9493032Simpchar	*getenv(const char *);
9593032Simplong	 labs(long) __pure2;
9693032Simpldiv_t	 ldiv(long, long) __pure2;
97187961Sdasvoid	*malloc(size_t) __malloc_like;
98103728Swollmanint	 mblen(const char *, size_t);
99103766Sbdesize_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
100103728Swollmanint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
10193032Simpvoid	 qsort(void *, size_t, size_t,
10293032Simp	    int (*)(const void *, const void *));
10393032Simpint	 rand(void);
10493032Simpvoid	*realloc(void *, size_t);
10593032Simpvoid	 srand(unsigned);
106103766Sbdedouble	 strtod(const char * __restrict, char ** __restrict);
107112163Sdasfloat	 strtof(const char * __restrict, char ** __restrict);
108103766Sbdelong	 strtol(const char * __restrict, char ** __restrict, int);
109112163Sdaslong double
110112163Sdas	 strtold(const char * __restrict, char ** __restrict);
1111539Srgrimesunsigned long
112103012Stjr	 strtoul(const char * __restrict, char ** __restrict, int);
11393032Simpint	 system(const char *);
11493032Simpint	 wctomb(char *, wchar_t);
115103012Stjrsize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
1161539Srgrimes
117103728Swollman/*
118103728Swollman * Functions added in C99 which we make conditionally available in the
119103728Swollman * BSD^C89 namespace if the compiler supports `long long'.
120103728Swollman * The #if test is more complicated than it ought to be because
121103728Swollman * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
122103728Swollman * is not supported in the compilation environment (which therefore means
123103728Swollman * that it can't really be ISO C99).
124103728Swollman *
125103728Swollman * (The only other extension made by C99 in thie header is _Exit().)
126103728Swollman */
127103728Swollman#if __ISO_C_VISIBLE >= 1999
128103728Swollman#ifdef __LONG_LONG_SUPPORTED
129103728Swollman/* LONGLONG */
130103728Swollmantypedef struct {
131103728Swollman	long long quot;
132103728Swollman	long long rem;
133103728Swollman} lldiv_t;
13469201Sphk
135103728Swollman/* LONGLONG */
136103728Swollmanlong long
137103728Swollman	 atoll(const char *);
138103728Swollman/* LONGLONG */
139103728Swollmanlong long
140103728Swollman	 llabs(long long) __pure2;
141103728Swollman/* LONGLONG */
142103728Swollmanlldiv_t	 lldiv(long long, long long) __pure2;
143103728Swollman/* LONGLONG */
144103766Sbdelong long
145103766Sbde	 strtoll(const char * __restrict, char ** __restrict, int);
146103728Swollman/* LONGLONG */
147103728Swollmanunsigned long long
148103766Sbde	 strtoull(const char * __restrict, char ** __restrict, int);
149103728Swollman#endif /* __LONG_LONG_SUPPORTED */
150103728Swollman
151103766Sbdevoid	 _Exit(int) __dead2;
152103728Swollman#endif /* __ISO_C_VISIBLE >= 1999 */
153103728Swollman
154103728Swollman/*
155103728Swollman * Extensions made by POSIX relative to C.  We don't know yet which edition
156103728Swollman * of POSIX made these extensions, so assume they've always been there until
157103728Swollman * research can be done.
158103728Swollman */
159103728Swollman#if __POSIX_VISIBLE /* >= ??? */
160154250Sjasoneint	 posix_memalign(void **, size_t, size_t); /* (ADV) */
161103728Swollmanint	 rand_r(unsigned *);			/* (TSF) */
16293032Simpint	 setenv(const char *, const char *, int);
163171195Sscfint	 unsetenv(const char *);
164103728Swollman#endif
1651539Srgrimes
166189349Sdas#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
167189349Sdasint	 getsubopt(char **, char *const *, char **);
168189349Sdas#ifndef _MKDTEMP_DECLARED
169189349Sdaschar	*mkdtemp(char *);
170189349Sdas#define	_MKDTEMP_DECLARED
171189349Sdas#endif
172189349Sdas#ifndef _MKSTEMP_DECLARED
173189349Sdasint	 mkstemp(char *);
174189349Sdas#define	_MKSTEMP_DECLARED
175189349Sdas#endif
176189349Sdas#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
177189349Sdas
178103728Swollman/*
179103728Swollman * The only changes to the XSI namespace in revision 6 were the deletion
180103728Swollman * of the ttyslot() and valloc() functions, which FreeBSD never declared
181103728Swollman * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
182103728Swollman * FreeBSD also does not have, and mktemp(), are to be deleted.
183103728Swollman */
184103728Swollman#if __XSI_VISIBLE
185103728Swollman/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
186153707Strhodeslong	 a64l(const char *);
18793032Simpdouble	 drand48(void);
188103766Sbde/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
18993032Simpdouble	 erand48(unsigned short[3]);
190103766Sbde/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
191103766Sbde/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
192108574Sjmallettint	 grantpt(int);
193103728Swollmanchar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
19493032Simplong	 jrand48(unsigned short[3]);
195153707Strhodeschar	*l64a(long);
19693032Simpvoid	 lcong48(unsigned short[7]);
19793032Simplong	 lrand48(void);
198189782Sdas#if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600)
199103728Swollmanchar	*mktemp(char *);
200103766Sbde#define	_MKTEMP_DECLARED
201103728Swollman#endif
20293032Simplong	 mrand48(void);
20393032Simplong	 nrand48(unsigned short[3]);
204108574Sjmallettint	 posix_openpt(int);
205108574Sjmallettchar	*ptsname(int);
206171195Sscfint	 putenv(char *);
207103728Swollmanlong	 random(void);
208103728Swollmanchar	*realpath(const char *, char resolved_path[]);
2097865Sbdeunsigned short
21093032Simp	*seed48(unsigned short[3]);
211103728Swollman#ifndef _SETKEY_DECLARED
212103728Swollmanint	 setkey(const char *);
213103728Swollman#define	_SETKEY_DECLARED
214103728Swollman#endif
215103728Swollmanchar	*setstate(/* const */ char *);
21693032Simpvoid	 srand48(long);
217103728Swollmanvoid	 srandom(unsigned long);
218108574Sjmallettint	 unlockpt(int);
219103728Swollman#endif /* __XSI_VISIBLE */
2204749Sats
221103728Swollman#if __BSD_VISIBLE
222103728Swollmanextern const char *_malloc_options;
223103766Sbdeextern void (*_malloc_message)(const char *, const char *, const char *,
224103766Sbde	    const char *);
225103728Swollman
226116397Sdes/*
227116397Sdes * The alloca() function can't be implemented in C, and on some
228116397Sdes * platforms it can't be implemented at all as a callable function.
229116397Sdes * The GNU C compiler provides a built-in alloca() which we can use;
230116397Sdes * in all other cases, provide a prototype, mainly to pacify various
231116397Sdes * incarnations of lint.  On platforms where alloca() is not in libc,
232116397Sdes * programs which use it will fail to link when compiled with non-GNU
233116397Sdes * compilers.
234116397Sdes */
235116831Sobrien#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
236116831Sobrien#undef  alloca	/* some GNU bits try to get cute and define this on their own */
237116397Sdes#define alloca(sz) __builtin_alloca(sz)
238116831Sobrien#elif defined(lint)
239116831Sobrienvoid	*alloca(size_t);
240116397Sdes#endif
241116397Sdes
242189820Sdasvoid	 abort2(const char *, int, void **) __dead2;
24341927Sdt__uint32_t
24493032Simp	 arc4random(void);
245180658Sachevoid	 arc4random_addrandom(unsigned char *, int);
246180658Sachevoid	 arc4random_buf(void *, size_t);
24793032Simpvoid	 arc4random_stir(void);
248180689Sache__uint32_t
249180689Sache	 arc4random_uniform(__uint32_t);
250108445Sobrienchar	*getbsize(int *, long *);
251103728Swollman					/* getcap(3) functions */
25293032Simpchar	*cgetcap(char *, const char *, int);
25393032Simpint	 cgetclose(void);
25493032Simpint	 cgetent(char **, char **, const char *);
25593032Simpint	 cgetfirst(char **, char **);
25693032Simpint	 cgetmatch(const char *, const char *);
25793032Simpint	 cgetnext(char **, char **);
25893032Simpint	 cgetnum(char *, const char *, long *);
25993032Simpint	 cgetset(const char *);
26093032Simpint	 cgetstr(char *, const char *, char **);
26193032Simpint	 cgetustr(char *, const char *, char **);
2621539Srgrimes
26393032Simpint	 daemon(int, int);
264150052Sstefanfchar	*devname(__dev_t, __mode_t);
265150052Sstefanfchar 	*devname_r(__dev_t, __mode_t, char *, int);
266188497Sedchar	*fdevname(int);
267188497Sedchar 	*fdevname_r(int, char *, int);
26893032Simpint	 getloadavg(double [], int);
26988399Smike__const char *
27093032Simp	 getprogname(void);
2711539Srgrimes
27293032Simpint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
273153707Strhodesint	 l64a_r(long, char *, int);
27493032Simpint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
275103164Swollmanvoid	 qsort_r(void *, size_t, size_t, void *,
276103164Swollman	    int (*)(void *, const void *, const void *));
27793032Simpint	 radixsort(const unsigned char **, int, const unsigned char *,
27893032Simp	    unsigned);
27993032Simpvoid    *reallocf(void *, size_t);
280139922Stjrint	 rpmatch(const char *);
28193032Simpvoid	 setprogname(const char *);
282103164Swollmanint	 sradixsort(const unsigned char **, int, const unsigned char *,
283103164Swollman	    unsigned);
28493032Simpvoid	 sranddev(void);
28593032Simpvoid	 srandomdev(void);
286156707Sandrelong long
287156707Sandre	strtonum(const char *, long long, long long, const char **);
288103728Swollman
289103728Swollman/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
290103766Sbde__int64_t
291103766Sbde	 strtoq(const char *, char **, int);
29241927Sdt__uint64_t
29393032Simp	 strtouq(const char *, char **, int);
294126136Sache
295126136Sacheextern char *suboptarg;			/* getsubopt(3) external variable */
296103728Swollman#endif /* __BSD_VISIBLE */
2971539Srgrimes__END_DECLS
2981539Srgrimes
2997865Sbde#endif /* !_STDLIB_H_ */
300