stdlib.h revision 103728
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 103728 2002-09-21 02:03:58Z wollman $
351539Srgrimes */
361539Srgrimes
371539Srgrimes#ifndef _STDLIB_H_
387865Sbde#define	_STDLIB_H_
391539Srgrimes
4033861Sbde#include <sys/cdefs.h>
41102227Smike#include <sys/_types.h>
4233861Sbde
43103728Swollman#if __BSD_VISIBLE
44102227Smike#ifndef _RUNE_T_DECLARED
45102227Smiketypedef	__rune_t	rune_t;
46102227Smike#define	_RUNE_T_DECLARED
4715483Sbde#endif
4815483Sbde#endif
4915483Sbde
50102227Smike#ifndef _SIZE_T_DECLARED
51102227Smiketypedef	__size_t	size_t;
52102227Smike#define	_SIZE_T_DECLARED
531539Srgrimes#endif
541539Srgrimes
5599640Sobrien#ifndef	__cplusplus
56102227Smike#ifndef _WCHAR_T_DECLARED
57102227Smiketypedef	__wchar_t	wchar_t;
58102227Smike#define	_WCHAR_T_DECLARED
591539Srgrimes#endif
6099640Sobrien#endif
611539Srgrimes
621539Srgrimestypedef struct {
631539Srgrimes	int quot;		/* quotient */
641539Srgrimes	int rem;		/* remainder */
651539Srgrimes} div_t;
661539Srgrimes
671539Srgrimestypedef struct {
681539Srgrimes	long quot;		/* quotient */
691539Srgrimes	long rem;		/* remainder */
701539Srgrimes} ldiv_t;
711539Srgrimes
721539Srgrimes#ifndef NULL
731539Srgrimes#define	NULL	0
741539Srgrimes#endif
751539Srgrimes
761539Srgrimes#define	EXIT_FAILURE	1
771539Srgrimes#define	EXIT_SUCCESS	0
781539Srgrimes
791539Srgrimes#define	RAND_MAX	0x7fffffff
801539Srgrimes
811539Srgrimesextern int __mb_cur_max;
821539Srgrimes#define	MB_CUR_MAX	__mb_cur_max
831539Srgrimes
841539Srgrimes__BEGIN_DECLS
8593032Simpvoid	 abort(void) __dead2;
8693032Simpint	 abs(int) __pure2;
8793032Simpint	 atexit(void (*)(void));
8893032Simpdouble	 atof(const char *);
8993032Simpint	 atoi(const char *);
9093032Simplong	 atol(const char *);
9193032Simpvoid	*bsearch(const void *, const void *, size_t,
9293032Simp	    size_t, int (*)(const void *, const void *));
9393032Simpvoid	*calloc(size_t, size_t);
9493032Simpdiv_t	 div(int, int) __pure2;
9593032Simpvoid	 exit(int) __dead2;
9693032Simpvoid	 free(void *);
9793032Simpchar	*getenv(const char *);
9893032Simplong	 labs(long) __pure2;
9993032Simpldiv_t	 ldiv(long, long) __pure2;
10093032Simpvoid	*malloc(size_t);
101103728Swollmanint	 mblen(const char *, size_t);
102103728Swollmansize_t	 mbstowcs(wchar_t *__restrict , const char *__restrict, size_t);
103103728Swollmanint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
10493032Simpvoid	 qsort(void *, size_t, size_t,
10593032Simp	    int (*)(const void *, const void *));
10693032Simpint	 rand(void);
10793032Simpvoid	*realloc(void *, size_t);
10893032Simpvoid	 srand(unsigned);
109103728Swollmandouble	 strtod(const char *__restrict, char **__restrict);
110103728Swollman/* float strtof(const char *__restrict, char **__restrict); */
111103728Swollmanlong	 strtol(const char *__restrict, char **__restrict, int);
112103728Swollman/* long double
113103728Swollman	 strtold(const char *__restrict, char **__restrict); */
1141539Srgrimesunsigned long
115103012Stjr	 strtoul(const char * __restrict, char ** __restrict, int);
11693032Simpint	 system(const char *);
11793032Simpint	 wctomb(char *, wchar_t);
118103012Stjrsize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
1191539Srgrimes
120103728Swollman/*
121103728Swollman * Functions added in C99 which we make conditionally available in the
122103728Swollman * BSD^C89 namespace if the compiler supports `long long'.
123103728Swollman * The #if test is more complicated than it ought to be because
124103728Swollman * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
125103728Swollman * is not supported in the compilation environment (which therefore means
126103728Swollman * that it can't really be ISO C99).
127103728Swollman *
128103728Swollman * (The only other extension made by C99 in thie header is _Exit().)
129103728Swollman */
130103728Swollman#if __ISO_C_VISIBLE >= 1999
131103728Swollman#ifdef __LONG_LONG_SUPPORTED
132103728Swollman/* LONGLONG */
133103728Swollmantypedef struct {
134103728Swollman	long long quot;
135103728Swollman	long long rem;
136103728Swollman} lldiv_t;
13769201Sphk
138103728Swollman/* LONGLONG */
139103728Swollmanlong long
140103728Swollman	 atoll(const char *);
141103728Swollman/* LONGLONG */
142103728Swollmanlong long
143103728Swollman	 llabs(long long) __pure2;
144103728Swollman/* LONGLONG */
145103728Swollmanlldiv_t	 lldiv(long long, long long) __pure2;
146103728Swollman/* LONGLONG */
147103728Swollmanlong long
148103728Swollman	 strtoll(const char *__restrict, char **__restrict, int);
149103728Swollman/* LONGLONG */
150103728Swollmanunsigned long long
151103728Swollman	 strtoull(const char *__restrict, char **__restrict, int);
152103728Swollman#endif /* __LONG_LONG_SUPPORTED */
153103728Swollman
154103728Swollmanvoid	_Exit(int) __dead2;
155103728Swollman#endif /* __ISO_C_VISIBLE >= 1999 */
156103728Swollman
157103728Swollman/*
158103728Swollman * Extensions made by POSIX relative to C.  We don't know yet which edition
159103728Swollman * of POSIX made these extensions, so assume they've always been there until
160103728Swollman * research can be done.
161103728Swollman */
162103728Swollman#if __POSIX_VISIBLE /* >= ??? */
163103728Swollman/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
164103728Swollmanint	 rand_r(unsigned *);			/* (TSF) */
16593032Simpint	 setenv(const char *, const char *, int);
166103728Swollmanvoid	 unsetenv(const char *);
167103728Swollman#endif
1681539Srgrimes
169103728Swollman/*
170103728Swollman * The only changes to the XSI namespace in revision 6 were the deletion
171103728Swollman * of the ttyslot() and valloc() functions, which FreeBSD never declared
172103728Swollman * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
173103728Swollman * FreeBSD also does not have, and mktemp(), are to be deleted.
174103728Swollman */
175103728Swollman#if __XSI_VISIBLE
176103728Swollman/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
177103728Swollman/* long	 a64l(const char *); */
17893032Simpdouble	 drand48(void);
179103728Swollman/* char	*ecvt(double, int, int *__restrict, int *__restrict); */
18093032Simpdouble	 erand48(unsigned short[3]);
181103728Swollman/* char	*fcvt(double, int, int *__restrict, int *__restrict); */
182103728Swollman/* char	*gcvt(double, int, int *__restrict, int *__restrict); */
183103728Swollman#ifndef _GETSUBOPT_DECLARED
184103728Swollmanint	 getsubopt(char **, char *const *, char **);
185103728Swollman#define	_GETSUBOPT_DECLARED
186103728Swollman#endif
187103728Swollman/* int	 grantpt(int); */
188103728Swollmanchar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
18993032Simplong	 jrand48(unsigned short[3]);
190103728Swollman/* char	*l64a(long); */
19193032Simpvoid	 lcong48(unsigned short[7]);
19293032Simplong	 lrand48(void);
193103728Swollman#ifndef _MKSTEMP_DECLARED
194103728Swollmanint	 mkstemp(char *);
195103728Swollman#define	_MKSTEMP_DECLARED
196103728Swollman#endif
197103728Swollman#ifndef _MKTEMP_DECLARED
198103728Swollmanchar	*mktemp(char *);
199103728Swollman#define _MKTEMP_DECLARED
200103728Swollman#endif
20193032Simplong	 mrand48(void);
20293032Simplong	 nrand48(unsigned short[3]);
203103728Swollman/* int	 posix_openpt(int); */
204103728Swollman/* char	*ptsname(int); */
205103728Swollmanint	 putenv(const char *);
206103728Swollmanlong	 random(void);
207103728Swollmanchar	*realpath(const char *, char resolved_path[]);
2087865Sbdeunsigned short
20993032Simp	*seed48(unsigned short[3]);
210103728Swollman#ifndef _SETKEY_DECLARED
211103728Swollmanint	 setkey(const char *);
212103728Swollman#define	_SETKEY_DECLARED
213103728Swollman#endif
214103728Swollmanchar	*setstate(/* const */ char *);
21593032Simpvoid	 srand48(long);
216103728Swollmanvoid	 srandom(unsigned long);
217103728Swollman/* int	 unlockpt(int); */
218103728Swollman#endif /* __XSI_VISIBLE */
2194749Sats
220103728Swollman
221103728Swollman#if __BSD_VISIBLE
222103728Swollmanextern const char *_malloc_options;
223103728Swollmanextern void (*_malloc_message)(const char *, const char *, const char *, const char *);
224103728Swollman
22593032Simpvoid	*alloca(size_t);		/* built-in for gcc */
22641927Sdt__uint32_t
22793032Simp	 arc4random(void);
22893032Simpvoid	 arc4random_addrandom(unsigned char *dat, int datlen);
22993032Simpvoid	 arc4random_stir(void);
23093032Simpchar	*getbsize(int *, long *);
231103728Swollman					/* getcap(3) functions */
23293032Simpchar	*cgetcap(char *, const char *, int);
23393032Simpint	 cgetclose(void);
23493032Simpint	 cgetent(char **, char **, const char *);
23593032Simpint	 cgetfirst(char **, char **);
23693032Simpint	 cgetmatch(const char *, const char *);
23793032Simpint	 cgetnext(char **, char **);
23893032Simpint	 cgetnum(char *, const char *, long *);
23993032Simpint	 cgetset(const char *);
24093032Simpint	 cgetstr(char *, const char *, char **);
24193032Simpint	 cgetustr(char *, const char *, char **);
2421539Srgrimes
24393032Simpint	 daemon(int, int);
24493032Simpchar	*devname(int, int);
24593032Simpint	 getloadavg(double [], int);
24688399Smike__const char *
24793032Simp	 getprogname(void);
2481539Srgrimes
24993032Simpint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
25093032Simpint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
251103164Swollmanvoid	 qsort_r(void *, size_t, size_t, void *,
252103164Swollman	    int (*)(void *, const void *, const void *));
25393032Simpint	 radixsort(const unsigned char **, int, const unsigned char *,
25493032Simp	    unsigned);
25593032Simpvoid    *reallocf(void *, size_t);
25693032Simpvoid	 setprogname(const char *);
257103164Swollmanint	 sradixsort(const unsigned char **, int, const unsigned char *,
258103164Swollman	    unsigned);
25993032Simpvoid	 sranddev(void);
26093032Simpvoid	 srandomdev(void);
261103728Swollman
262103728Swollman/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
26393032Simp__int64_t	 strtoq(const char *, char **, int);
26441927Sdt__uint64_t
26593032Simp	 strtouq(const char *, char **, int);
266103728Swollman#endif /* __BSD_VISIBLE */
2671539Srgrimes__END_DECLS
2681539Srgrimes
2697865Sbde#endif /* !_STDLIB_H_ */
270