stdlib.h revision 103728
1/*-
2 * Copyright (c) 1990, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34 * $FreeBSD: head/include/stdlib.h 103728 2002-09-21 02:03:58Z wollman $
35 */
36
37#ifndef _STDLIB_H_
38#define	_STDLIB_H_
39
40#include <sys/cdefs.h>
41#include <sys/_types.h>
42
43#if __BSD_VISIBLE
44#ifndef _RUNE_T_DECLARED
45typedef	__rune_t	rune_t;
46#define	_RUNE_T_DECLARED
47#endif
48#endif
49
50#ifndef _SIZE_T_DECLARED
51typedef	__size_t	size_t;
52#define	_SIZE_T_DECLARED
53#endif
54
55#ifndef	__cplusplus
56#ifndef _WCHAR_T_DECLARED
57typedef	__wchar_t	wchar_t;
58#define	_WCHAR_T_DECLARED
59#endif
60#endif
61
62typedef struct {
63	int quot;		/* quotient */
64	int rem;		/* remainder */
65} div_t;
66
67typedef struct {
68	long quot;		/* quotient */
69	long rem;		/* remainder */
70} ldiv_t;
71
72#ifndef NULL
73#define	NULL	0
74#endif
75
76#define	EXIT_FAILURE	1
77#define	EXIT_SUCCESS	0
78
79#define	RAND_MAX	0x7fffffff
80
81extern int __mb_cur_max;
82#define	MB_CUR_MAX	__mb_cur_max
83
84__BEGIN_DECLS
85void	 abort(void) __dead2;
86int	 abs(int) __pure2;
87int	 atexit(void (*)(void));
88double	 atof(const char *);
89int	 atoi(const char *);
90long	 atol(const char *);
91void	*bsearch(const void *, const void *, size_t,
92	    size_t, int (*)(const void *, const void *));
93void	*calloc(size_t, size_t);
94div_t	 div(int, int) __pure2;
95void	 exit(int) __dead2;
96void	 free(void *);
97char	*getenv(const char *);
98long	 labs(long) __pure2;
99ldiv_t	 ldiv(long, long) __pure2;
100void	*malloc(size_t);
101int	 mblen(const char *, size_t);
102size_t	 mbstowcs(wchar_t *__restrict , const char *__restrict, size_t);
103int	 mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
104void	 qsort(void *, size_t, size_t,
105	    int (*)(const void *, const void *));
106int	 rand(void);
107void	*realloc(void *, size_t);
108void	 srand(unsigned);
109double	 strtod(const char *__restrict, char **__restrict);
110/* float strtof(const char *__restrict, char **__restrict); */
111long	 strtol(const char *__restrict, char **__restrict, int);
112/* long double
113	 strtold(const char *__restrict, char **__restrict); */
114unsigned long
115	 strtoul(const char * __restrict, char ** __restrict, int);
116int	 system(const char *);
117int	 wctomb(char *, wchar_t);
118size_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
119
120/*
121 * Functions added in C99 which we make conditionally available in the
122 * BSD^C89 namespace if the compiler supports `long long'.
123 * The #if test is more complicated than it ought to be because
124 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
125 * is not supported in the compilation environment (which therefore means
126 * that it can't really be ISO C99).
127 *
128 * (The only other extension made by C99 in thie header is _Exit().)
129 */
130#if __ISO_C_VISIBLE >= 1999
131#ifdef __LONG_LONG_SUPPORTED
132/* LONGLONG */
133typedef struct {
134	long long quot;
135	long long rem;
136} lldiv_t;
137
138/* LONGLONG */
139long long
140	 atoll(const char *);
141/* LONGLONG */
142long long
143	 llabs(long long) __pure2;
144/* LONGLONG */
145lldiv_t	 lldiv(long long, long long) __pure2;
146/* LONGLONG */
147long long
148	 strtoll(const char *__restrict, char **__restrict, int);
149/* LONGLONG */
150unsigned long long
151	 strtoull(const char *__restrict, char **__restrict, int);
152#endif /* __LONG_LONG_SUPPORTED */
153
154void	_Exit(int) __dead2;
155#endif /* __ISO_C_VISIBLE >= 1999 */
156
157/*
158 * Extensions made by POSIX relative to C.  We don't know yet which edition
159 * of POSIX made these extensions, so assume they've always been there until
160 * research can be done.
161 */
162#if __POSIX_VISIBLE /* >= ??? */
163/* int	 posix_memalign(void **, size_t, size_t); (ADV) */
164int	 rand_r(unsigned *);			/* (TSF) */
165int	 setenv(const char *, const char *, int);
166void	 unsetenv(const char *);
167#endif
168
169/*
170 * The only changes to the XSI namespace in revision 6 were the deletion
171 * of the ttyslot() and valloc() functions, which FreeBSD never declared
172 * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
173 * FreeBSD also does not have, and mktemp(), are to be deleted.
174 */
175#if __XSI_VISIBLE
176/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
177/* long	 a64l(const char *); */
178double	 drand48(void);
179/* char	*ecvt(double, int, int *__restrict, int *__restrict); */
180double	 erand48(unsigned short[3]);
181/* char	*fcvt(double, int, int *__restrict, int *__restrict); */
182/* char	*gcvt(double, int, int *__restrict, int *__restrict); */
183#ifndef _GETSUBOPT_DECLARED
184int	 getsubopt(char **, char *const *, char **);
185#define	_GETSUBOPT_DECLARED
186#endif
187/* int	 grantpt(int); */
188char	*initstate(unsigned long /* XSI requires u_int */, char *, long);
189long	 jrand48(unsigned short[3]);
190/* char	*l64a(long); */
191void	 lcong48(unsigned short[7]);
192long	 lrand48(void);
193#ifndef _MKSTEMP_DECLARED
194int	 mkstemp(char *);
195#define	_MKSTEMP_DECLARED
196#endif
197#ifndef _MKTEMP_DECLARED
198char	*mktemp(char *);
199#define _MKTEMP_DECLARED
200#endif
201long	 mrand48(void);
202long	 nrand48(unsigned short[3]);
203/* int	 posix_openpt(int); */
204/* char	*ptsname(int); */
205int	 putenv(const char *);
206long	 random(void);
207char	*realpath(const char *, char resolved_path[]);
208unsigned short
209	*seed48(unsigned short[3]);
210#ifndef _SETKEY_DECLARED
211int	 setkey(const char *);
212#define	_SETKEY_DECLARED
213#endif
214char	*setstate(/* const */ char *);
215void	 srand48(long);
216void	 srandom(unsigned long);
217/* int	 unlockpt(int); */
218#endif /* __XSI_VISIBLE */
219
220
221#if __BSD_VISIBLE
222extern const char *_malloc_options;
223extern void (*_malloc_message)(const char *, const char *, const char *, const char *);
224
225void	*alloca(size_t);		/* built-in for gcc */
226__uint32_t
227	 arc4random(void);
228void	 arc4random_addrandom(unsigned char *dat, int datlen);
229void	 arc4random_stir(void);
230char	*getbsize(int *, long *);
231					/* getcap(3) functions */
232char	*cgetcap(char *, const char *, int);
233int	 cgetclose(void);
234int	 cgetent(char **, char **, const char *);
235int	 cgetfirst(char **, char **);
236int	 cgetmatch(const char *, const char *);
237int	 cgetnext(char **, char **);
238int	 cgetnum(char *, const char *, long *);
239int	 cgetset(const char *);
240int	 cgetstr(char *, const char *, char **);
241int	 cgetustr(char *, const char *, char **);
242
243int	 daemon(int, int);
244char	*devname(int, int);
245int	 getloadavg(double [], int);
246__const char *
247	 getprogname(void);
248
249int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
250int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
251void	 qsort_r(void *, size_t, size_t, void *,
252	    int (*)(void *, const void *, const void *));
253int	 radixsort(const unsigned char **, int, const unsigned char *,
254	    unsigned);
255void    *reallocf(void *, size_t);
256void	 setprogname(const char *);
257int	 sradixsort(const unsigned char **, int, const unsigned char *,
258	    unsigned);
259void	 sranddev(void);
260void	 srandomdev(void);
261
262/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
263__int64_t	 strtoq(const char *, char **, int);
264__uint64_t
265	 strtouq(const char *, char **, int);
266#endif /* __BSD_VISIBLE */
267__END_DECLS
268
269#endif /* !_STDLIB_H_ */
270