stdlib.h revision 116833
10SN/A/*-
21472SN/A * Copyright (c) 1990, 1993
30SN/A *	The Regents of the University of California.  All rights reserved.
40SN/A *
50SN/A * Redistribution and use in source and binary forms, with or without
60SN/A * modification, are permitted provided that the following conditions
70SN/A * are met:
80SN/A * 1. Redistributions of source code must retain the above copyright
90SN/A *    notice, this list of conditions and the following disclaimer.
100SN/A * 2. Redistributions in binary form must reproduce the above copyright
110SN/A *    notice, this list of conditions and the following disclaimer in the
120SN/A *    documentation and/or other materials provided with the distribution.
130SN/A * 3. All advertising materials mentioning features or use of this software
140SN/A *    must display the following acknowledgement:
150SN/A *	This product includes software developed by the University of
160SN/A *	California, Berkeley and its contributors.
170SN/A * 4. Neither the name of the University nor the names of its contributors
180SN/A *    may be used to endorse or promote products derived from this software
191472SN/A *    without specific prior written permission.
201472SN/A *
211472SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
220SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
230SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
240SN/A * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
250SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
260SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
270SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
280SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
290SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
300SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
310SN/A * SUCH DAMAGE.
320SN/A *
330SN/A *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
340SN/A * $FreeBSD: head/include/stdlib.h 116833 2003-06-25 19:06:40Z obrien $
350SN/A */
360SN/A
370SN/A#ifndef _STDLIB_H_
380SN/A#define	_STDLIB_H_
390SN/A
400SN/A#include <sys/cdefs.h>
410SN/A#include <sys/_types.h>
420SN/A
430SN/A#if __BSD_VISIBLE
440SN/A#ifndef _RUNE_T_DECLARED
450SN/Atypedef	__rune_t	rune_t;
460SN/A#define	_RUNE_T_DECLARED
470SN/A#endif
480SN/A#endif
490SN/A
500SN/A#ifndef _SIZE_T_DECLARED
510SN/Atypedef	__size_t	size_t;
520SN/A#define	_SIZE_T_DECLARED
530SN/A#endif
540SN/A
550SN/A#ifndef	__cplusplus
560SN/A#ifndef _WCHAR_T_DECLARED
570SN/Atypedef	__wchar_t	wchar_t;
580SN/A#define	_WCHAR_T_DECLARED
590SN/A#endif
600SN/A#endif
610SN/A
620SN/Atypedef struct {
630SN/A	int	quot;		/* quotient */
640SN/A	int	rem;		/* remainder */
650SN/A} div_t;
660SN/A
670SN/Atypedef struct {
680SN/A	long	quot;
690SN/A	long	rem;
700SN/A} ldiv_t;
710SN/A
720SN/A#ifndef NULL
730SN/A#define	NULL	0
740SN/A#endif
750SN/A
760SN/A#define	EXIT_FAILURE	1
770SN/A#define	EXIT_SUCCESS	0
780SN/A
790SN/A#define	RAND_MAX	0x7fffffff
800SN/A
810SN/Aextern int __mb_cur_max;
820SN/A#define	MB_CUR_MAX	__mb_cur_max
830SN/A
840SN/A__BEGIN_DECLS
850SN/Avoid	 abort(void) __dead2;
860SN/Aint	 abs(int) __pure2;
870SN/Aint	 atexit(void (*)(void));
880SN/Adouble	 atof(const char *);
890SN/Aint	 atoi(const char *);
900SN/Along	 atol(const char *);
910SN/Avoid	*bsearch(const void *, const void *, size_t,
920SN/A	    size_t, int (*)(const void *, const void *));
930SN/Avoid	*calloc(size_t, size_t);
940SN/Adiv_t	 div(int, int) __pure2;
950SN/Avoid	 exit(int) __dead2;
960SN/Avoid	 free(void *);
970SN/Achar	*getenv(const char *);
980SN/Along	 labs(long) __pure2;
990SN/Aldiv_t	 ldiv(long, long) __pure2;
1000SN/Avoid	*malloc(size_t);
1010SN/Aint	 mblen(const char *, size_t);
1020SN/Asize_t	 mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
1030SN/Aint	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
1040SN/Avoid	 qsort(void *, size_t, size_t,
1050SN/A	    int (*)(const void *, const void *));
1060SN/Aint	 rand(void);
1070SN/Avoid	*realloc(void *, size_t);
1080SN/Avoid	 srand(unsigned);
1090SN/Adouble	 strtod(const char * __restrict, char ** __restrict);
1100SN/Afloat	 strtof(const char * __restrict, char ** __restrict);
1110SN/Along	 strtol(const char * __restrict, char ** __restrict, int);
1120SN/Along double
1130SN/A	 strtold(const char * __restrict, char ** __restrict);
1140SN/Aunsigned long
1150SN/A	 strtoul(const char * __restrict, char ** __restrict, int);
1160SN/Aint	 system(const char *);
1170SN/Aint	 wctomb(char *, wchar_t);
1180SN/Asize_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
1190SN/A
1200SN/A/*
1210SN/A * Functions added in C99 which we make conditionally available in the
1220SN/A * BSD^C89 namespace if the compiler supports `long long'.
1230SN/A * The #if test is more complicated than it ought to be because
1240SN/A * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
1250SN/A * is not supported in the compilation environment (which therefore means
1260SN/A * that it can't really be ISO C99).
1270SN/A *
1280SN/A * (The only other extension made by C99 in thie header is _Exit().)
1290SN/A */
1300SN/A#if __ISO_C_VISIBLE >= 1999
1310SN/A#ifdef __LONG_LONG_SUPPORTED
1320SN/A/* LONGLONG */
1330SN/Atypedef struct {
1340SN/A	long long quot;
1350SN/A	long long rem;
1360SN/A} lldiv_t;
1370SN/A
1380SN/A/* LONGLONG */
1390SN/Along long
1400SN/A	 atoll(const char *);
1410SN/A/* LONGLONG */
1420SN/Along long
1430SN/A	 llabs(long long) __pure2;
1440SN/A/* LONGLONG */
1450SN/Alldiv_t	 lldiv(long long, long long) __pure2;
1460SN/A/* LONGLONG */
1470SN/Along long
1480SN/A	 strtoll(const char * __restrict, char ** __restrict, int);
1490SN/A/* LONGLONG */
1500SN/Aunsigned long long
1510SN/A	 strtoull(const char * __restrict, char ** __restrict, int);
1520SN/A#endif /* __LONG_LONG_SUPPORTED */
1530SN/A
1540SN/Avoid	 _Exit(int) __dead2;
1550SN/A#endif /* __ISO_C_VISIBLE >= 1999 */
1560SN/A
1570SN/A/*
1580SN/A * Extensions made by POSIX relative to C.  We don't know yet which edition
1590SN/A * of POSIX made these extensions, so assume they've always been there until
1600SN/A * research can be done.
1610SN/A */
1620SN/A#if __POSIX_VISIBLE /* >= ??? */
1630SN/A/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
1640SN/Aint	 rand_r(unsigned *);			/* (TSF) */
1650SN/Aint	 setenv(const char *, const char *, int);
1660SN/Avoid	 unsetenv(const char *);
1670SN/A#endif
1680SN/A
1690SN/A/*
1700SN/A * The only changes to the XSI namespace in revision 6 were the deletion
1710SN/A * of the ttyslot() and valloc() functions, which FreeBSD never declared
1720SN/A * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
1730SN/A * FreeBSD also does not have, and mktemp(), are to be deleted.
1740SN/A */
1750SN/A#if __XSI_VISIBLE
1760SN/A/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
1770SN/A/* long	 a64l(const char *); */
1780SN/Adouble	 drand48(void);
1790SN/A/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
1800SN/Adouble	 erand48(unsigned short[3]);
1810SN/A/* char	*fcvt(double, int, int * __restrict, int * __restrict); */
1820SN/A/* char	*gcvt(double, int, int * __restrict, int * __restrict); */
1830SN/A#ifndef _GETSUBOPT_DECLARED
1840SN/Aint	 getsubopt(char **, char *const *, char **);
1850SN/A#define	_GETSUBOPT_DECLARED
1860SN/A#endif
1870SN/Aint	 grantpt(int);
1880SN/Achar	*initstate(unsigned long /* XSI requires u_int */, char *, long);
1890SN/Along	 jrand48(unsigned short[3]);
1900SN/A/* char	*l64a(long); */
1910SN/Avoid	 lcong48(unsigned short[7]);
1920SN/Along	 lrand48(void);
1930SN/A#ifndef _MKSTEMP_DECLARED
1940SN/Aint	 mkstemp(char *);
1950SN/A#define	_MKSTEMP_DECLARED
1960SN/A#endif
1970SN/A#ifndef _MKTEMP_DECLARED
1980SN/Achar	*mktemp(char *);
1990SN/A#define	_MKTEMP_DECLARED
2000SN/A#endif
2010SN/Along	 mrand48(void);
2020SN/Along	 nrand48(unsigned short[3]);
2030SN/Aint	 posix_openpt(int);
2040SN/Achar	*ptsname(int);
2050SN/Aint	 putenv(const char *);
2060SN/Along	 random(void);
2070SN/Achar	*realpath(const char *, char resolved_path[]);
2080SN/Aunsigned short
2090SN/A	*seed48(unsigned short[3]);
2100SN/A#ifndef _SETKEY_DECLARED
2110SN/Aint	 setkey(const char *);
2120SN/A#define	_SETKEY_DECLARED
2130SN/A#endif
2140SN/Achar	*setstate(/* const */ char *);
2150SN/Avoid	 srand48(long);
2160SN/Avoid	 srandom(unsigned long);
2170SN/Aint	 unlockpt(int);
2180SN/A#endif /* __XSI_VISIBLE */
2190SN/A
2200SN/A#if __BSD_VISIBLE
2210SN/Aextern const char *_malloc_options;
2220SN/Aextern void (*_malloc_message)(const char *, const char *, const char *,
2230SN/A	    const char *);
2240SN/A
2250SN/A/*
2260SN/A * The alloca() function can't be implemented in C, and on some
2270SN/A * platforms it can't be implemented at all as a callable function.
2280SN/A * The GNU C compiler provides a built-in alloca() which we can use;
2290SN/A * in all other cases, provide a prototype, mainly to pacify various
2300SN/A * incarnations of lint.  On platforms where alloca() is not in libc,
2310SN/A * programs which use it will fail to link when compiled with non-GNU
2320SN/A * compilers.
2330SN/A */
2340SN/A#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
2350SN/A#undef  alloca	/* some GNU bits try to get cute and define this on their own */
2360SN/A#define alloca(sz) __builtin_alloca(sz)
2370SN/A#elif defined(lint)
2380SN/Avoid	*alloca(size_t);
2390SN/A#endif
2400SN/A
2410SN/A__uint32_t
2420SN/A	 arc4random(void);
2430SN/Avoid	 arc4random_addrandom(unsigned char *dat, int datlen);
2440SN/Avoid	 arc4random_stir(void);
2450SN/Achar	*getbsize(int *, long *);
2460SN/A					/* getcap(3) functions */
2470SN/Achar	*cgetcap(char *, const char *, int);
2480SN/Aint	 cgetclose(void);
2490SN/Aint	 cgetent(char **, char **, const char *);
2500SN/Aint	 cgetfirst(char **, char **);
2510SN/Aint	 cgetmatch(const char *, const char *);
2520SN/Aint	 cgetnext(char **, char **);
2530SN/Aint	 cgetnum(char *, const char *, long *);
2540SN/Aint	 cgetset(const char *);
2550SN/Aint	 cgetstr(char *, const char *, char **);
2560SN/Aint	 cgetustr(char *, const char *, char **);
2570SN/A
2580SN/Aint	 daemon(int, int);
2590SN/Achar	*devname(int, int);
2600SN/Achar 	*devname_r(int, int, char *, int);
2610SN/Aint	 getloadavg(double [], int);
2620SN/A__const char *
2630SN/A	 getprogname(void);
2640SN/A
2650SN/Aint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
2660SN/Aint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
2670SN/Avoid	 qsort_r(void *, size_t, size_t, void *,
2680SN/A	    int (*)(void *, const void *, const void *));
2690SN/Aint	 radixsort(const unsigned char **, int, const unsigned char *,
2700SN/A	    unsigned);
2710SN/Avoid    *reallocf(void *, size_t);
2720SN/Avoid	 setprogname(const char *);
2730SN/Aint	 sradixsort(const unsigned char **, int, const unsigned char *,
2740SN/A	    unsigned);
2750SN/Avoid	 sranddev(void);
276113SN/Avoid	 srandomdev(void);
277113SN/A
278113SN/A/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
279113SN/A__int64_t
2800SN/A	 strtoq(const char *, char **, int);
2810SN/A__uint64_t
2820SN/A	 strtouq(const char *, char **, int);
2830SN/A#endif /* __BSD_VISIBLE */
2840SN/A__END_DECLS
2850SN/A
2860SN/A#endif /* !_STDLIB_H_ */
2870SN/A