stdlib.h revision 139922
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 139922 2005-01-09 03:55:13Z tjr $
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 *));
9093032Simpvoid	*calloc(size_t, size_t);
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;
9793032Simpvoid	*malloc(size_t);
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 /* >= ??? */
160103728Swollman/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
161103728Swollmanint	 rand_r(unsigned *);			/* (TSF) */
16293032Simpint	 setenv(const char *, const char *, int);
163103728Swollmanvoid	 unsetenv(const char *);
164103728Swollman#endif
1651539Srgrimes
166103728Swollman/*
167103728Swollman * The only changes to the XSI namespace in revision 6 were the deletion
168103728Swollman * of the ttyslot() and valloc() functions, which FreeBSD never declared
169103728Swollman * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
170103728Swollman * FreeBSD also does not have, and mktemp(), are to be deleted.
171103728Swollman */
172103728Swollman#if __XSI_VISIBLE
173103728Swollman/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
174103728Swollman/* long	 a64l(const char *); */
17593032Simpdouble	 drand48(void);
176103766Sbde/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
17793032Simpdouble	 erand48(unsigned short[3]);
178103766Sbde/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
179103766Sbde/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
180103728Swollmanint	 getsubopt(char **, char *const *, char **);
181108574Sjmallettint	 grantpt(int);
182103728Swollmanchar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
18393032Simplong	 jrand48(unsigned short[3]);
184103728Swollman/* char	*l64a(long); */
18593032Simpvoid	 lcong48(unsigned short[7]);
18693032Simplong	 lrand48(void);
187103728Swollman#ifndef _MKSTEMP_DECLARED
188103728Swollmanint	 mkstemp(char *);
189103728Swollman#define	_MKSTEMP_DECLARED
190103728Swollman#endif
191103728Swollman#ifndef _MKTEMP_DECLARED
192103728Swollmanchar	*mktemp(char *);
193103766Sbde#define	_MKTEMP_DECLARED
194103728Swollman#endif
19593032Simplong	 mrand48(void);
19693032Simplong	 nrand48(unsigned short[3]);
197108574Sjmallettint	 posix_openpt(int);
198108574Sjmallettchar	*ptsname(int);
199103728Swollmanint	 putenv(const char *);
200103728Swollmanlong	 random(void);
201103728Swollmanchar	*realpath(const char *, char resolved_path[]);
2027865Sbdeunsigned short
20393032Simp	*seed48(unsigned short[3]);
204103728Swollman#ifndef _SETKEY_DECLARED
205103728Swollmanint	 setkey(const char *);
206103728Swollman#define	_SETKEY_DECLARED
207103728Swollman#endif
208103728Swollmanchar	*setstate(/* const */ char *);
20993032Simpvoid	 srand48(long);
210103728Swollmanvoid	 srandom(unsigned long);
211108574Sjmallettint	 unlockpt(int);
212103728Swollman#endif /* __XSI_VISIBLE */
2134749Sats
214103728Swollman#if __BSD_VISIBLE
215103728Swollmanextern const char *_malloc_options;
216103766Sbdeextern void (*_malloc_message)(const char *, const char *, const char *,
217103766Sbde	    const char *);
218103728Swollman
219116397Sdes/*
220116397Sdes * The alloca() function can't be implemented in C, and on some
221116397Sdes * platforms it can't be implemented at all as a callable function.
222116397Sdes * The GNU C compiler provides a built-in alloca() which we can use;
223116397Sdes * in all other cases, provide a prototype, mainly to pacify various
224116397Sdes * incarnations of lint.  On platforms where alloca() is not in libc,
225116397Sdes * programs which use it will fail to link when compiled with non-GNU
226116397Sdes * compilers.
227116397Sdes */
228116831Sobrien#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
229116831Sobrien#undef  alloca	/* some GNU bits try to get cute and define this on their own */
230116397Sdes#define alloca(sz) __builtin_alloca(sz)
231116831Sobrien#elif defined(lint)
232116831Sobrienvoid	*alloca(size_t);
233116397Sdes#endif
234116397Sdes
23541927Sdt__uint32_t
23693032Simp	 arc4random(void);
23793032Simpvoid	 arc4random_addrandom(unsigned char *dat, int datlen);
23893032Simpvoid	 arc4random_stir(void);
239108445Sobrienchar	*getbsize(int *, long *);
240103728Swollman					/* getcap(3) functions */
24193032Simpchar	*cgetcap(char *, const char *, int);
24293032Simpint	 cgetclose(void);
24393032Simpint	 cgetent(char **, char **, const char *);
24493032Simpint	 cgetfirst(char **, char **);
24593032Simpint	 cgetmatch(const char *, const char *);
24693032Simpint	 cgetnext(char **, char **);
24793032Simpint	 cgetnum(char *, const char *, long *);
24893032Simpint	 cgetset(const char *);
24993032Simpint	 cgetstr(char *, const char *, char **);
25093032Simpint	 cgetustr(char *, const char *, char **);
2511539Srgrimes
25293032Simpint	 daemon(int, int);
25393032Simpchar	*devname(int, int);
254116680Sdwmalonechar 	*devname_r(int, int, char *, int);
25593032Simpint	 getloadavg(double [], int);
25688399Smike__const char *
25793032Simp	 getprogname(void);
2581539Srgrimes
25993032Simpint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
26093032Simpint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
261103164Swollmanvoid	 qsort_r(void *, size_t, size_t, void *,
262103164Swollman	    int (*)(void *, const void *, const void *));
26393032Simpint	 radixsort(const unsigned char **, int, const unsigned char *,
26493032Simp	    unsigned);
26593032Simpvoid    *reallocf(void *, size_t);
266139922Stjrint	 rpmatch(const char *);
26793032Simpvoid	 setprogname(const char *);
268103164Swollmanint	 sradixsort(const unsigned char **, int, const unsigned char *,
269103164Swollman	    unsigned);
27093032Simpvoid	 sranddev(void);
27193032Simpvoid	 srandomdev(void);
272103728Swollman
273103728Swollman/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
274103766Sbde__int64_t
275103766Sbde	 strtoq(const char *, char **, int);
27641927Sdt__uint64_t
27793032Simp	 strtouq(const char *, char **, int);
278126136Sache
279126136Sacheextern char *suboptarg;			/* getsubopt(3) external variable */
280103728Swollman#endif /* __BSD_VISIBLE */
2811539Srgrimes__END_DECLS
2821539Srgrimes
2837865Sbde#endif /* !_STDLIB_H_ */
284