stdlib.h revision 93032
1168793Sthompsa/*-
2168793Sthompsa * Copyright (c) 1990, 1993
3168793Sthompsa *	The Regents of the University of California.  All rights reserved.
4168793Sthompsa *
5168793Sthompsa * Redistribution and use in source and binary forms, with or without
6168793Sthompsa * modification, are permitted provided that the following conditions
7168793Sthompsa * are met:
8168793Sthompsa * 1. Redistributions of source code must retain the above copyright
9168793Sthompsa *    notice, this list of conditions and the following disclaimer.
10168793Sthompsa * 2. Redistributions in binary form must reproduce the above copyright
11168793Sthompsa *    notice, this list of conditions and the following disclaimer in the
12168793Sthompsa *    documentation and/or other materials provided with the distribution.
13168793Sthompsa * 3. All advertising materials mentioning features or use of this software
14168793Sthompsa *    must display the following acknowledgement:
15168793Sthompsa *	This product includes software developed by the University of
16168793Sthompsa *	California, Berkeley and its contributors.
17168793Sthompsa * 4. Neither the name of the University nor the names of its contributors
18168793Sthompsa *    may be used to endorse or promote products derived from this software
19168793Sthompsa *    without specific prior written permission.
20168793Sthompsa *
21168793Sthompsa * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22168793Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23168793Sthompsa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24168793Sthompsa * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25168793Sthompsa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26168793Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27168793Sthompsa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28168793Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29168793Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30168793Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31168793Sthompsa * SUCH DAMAGE.
32171247Sthompsa *
33171247Sthompsa *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34168793Sthompsa * $FreeBSD: head/include/stdlib.h 93032 2002-03-23 17:24:55Z imp $
35168793Sthompsa */
36168793Sthompsa
37168793Sthompsa#ifndef _STDLIB_H_
38168793Sthompsa#define	_STDLIB_H_
39168793Sthompsa
40168793Sthompsa#include <sys/cdefs.h>
41168793Sthompsa
42168793Sthompsa#include <machine/ansi.h>
43168793Sthompsa
44168793Sthompsa#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
45168793Sthompsa#ifdef	_BSD_RUNE_T_
46168793Sthompsatypedef	_BSD_RUNE_T_	rune_t;
47168793Sthompsa#undef	_BSD_RUNE_T_
48168793Sthompsa#endif
49168793Sthompsa#endif
50168793Sthompsa
51168793Sthompsa#ifdef	_BSD_SIZE_T_
52168793Sthompsatypedef	_BSD_SIZE_T_	size_t;
53168793Sthompsa#undef	_BSD_SIZE_T_
54168793Sthompsa#endif
55168793Sthompsa
56168793Sthompsa#ifdef	_BSD_WCHAR_T_
57168793Sthompsatypedef	_BSD_WCHAR_T_	wchar_t;
58168793Sthompsa#undef	_BSD_WCHAR_T_
59168793Sthompsa#endif
60168793Sthompsa
61168793Sthompsatypedef struct {
62168793Sthompsa	int quot;		/* quotient */
63170603Sthompsa	int rem;		/* remainder */
64168793Sthompsa} div_t;
65168793Sthompsa
66168793Sthompsatypedef struct {
67168793Sthompsa	long quot;		/* quotient */
68168793Sthompsa	long rem;		/* remainder */
69168793Sthompsa} ldiv_t;
70170603Sthompsa
71170603Sthompsa#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
72170603Sthompsa#ifdef __LONG_LONG_SUPPORTED
73168793Sthompsatypedef struct {
74168793Sthompsa	long long quot;
75168793Sthompsa	long long rem;
76168793Sthompsa} lldiv_t;
77168793Sthompsa#endif
78168793Sthompsa#endif
79168793Sthompsa
80168793Sthompsa#ifndef NULL
81168793Sthompsa#define	NULL	0
82168793Sthompsa#endif
83168793Sthompsa
84171247Sthompsa#define	EXIT_FAILURE	1
85171247Sthompsa#define	EXIT_SUCCESS	0
86171247Sthompsa
87171247Sthompsa#define	RAND_MAX	0x7fffffff
88171247Sthompsa
89171247Sthompsaextern int __mb_cur_max;
90171247Sthompsa#define	MB_CUR_MAX	__mb_cur_max
91171247Sthompsa
92171247Sthompsa__BEGIN_DECLS
93171247Sthompsavoid	 abort(void) __dead2;
94171247Sthompsaint	 abs(int) __pure2;
95171247Sthompsaint	 atexit(void (*)(void));
96171247Sthompsadouble	 atof(const char *);
97171247Sthompsaint	 atoi(const char *);
98171247Sthompsalong	 atol(const char *);
99171247Sthompsavoid	*bsearch(const void *, const void *, size_t,
100171247Sthompsa	    size_t, int (*)(const void *, const void *));
101171247Sthompsavoid	*calloc(size_t, size_t);
102171247Sthompsadiv_t	 div(int, int) __pure2;
103171247Sthompsavoid	 exit(int) __dead2;
104171247Sthompsavoid	 free(void *);
105171247Sthompsachar	*getenv(const char *);
106171247Sthompsalong	 labs(long) __pure2;
107171247Sthompsaldiv_t	 ldiv(long, long) __pure2;
108171247Sthompsavoid	*malloc(size_t);
109171247Sthompsavoid	 qsort(void *, size_t, size_t,
110171247Sthompsa	    int (*)(const void *, const void *));
111171247Sthompsaint	 rand(void);
112168793Sthompsavoid	*realloc(void *, size_t);
113168793Sthompsavoid	 srand(unsigned);
114168793Sthompsadouble	 strtod(const char *, char **);
115170603Sthompsalong	 strtol(const char *, char **, int);
116168793Sthompsaunsigned long
117168793Sthompsa	 strtoul(const char *, char **, int);
118171247Sthompsaint	 system(const char *);
119168793Sthompsa
120168793Sthompsaint	 mblen(const char *, size_t);
121168793Sthompsasize_t	 mbstowcs(wchar_t *, const char *, size_t);
122168793Sthompsaint	 wctomb(char *, wchar_t);
123168793Sthompsaint	 mbtowc(wchar_t *, const char *, size_t);
124168793Sthompsasize_t	 wcstombs(char *, const wchar_t *, size_t);
125168793Sthompsa
126168793Sthompsa#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
127168793Sthompsaextern char *_malloc_options;
128168793Sthompsaextern void (*_malloc_message)(char *p1, char *p2, char *p3, char *p4);
129168793Sthompsa
130168793Sthompsaint	 putenv(const char *);
131168793Sthompsaint	 setenv(const char *, const char *, int);
132168793Sthompsa
133168793Sthompsadouble	 drand48(void);
134168793Sthompsadouble	 erand48(unsigned short[3]);
135168793Sthompsalong	 jrand48(unsigned short[3]);
136171247Sthompsavoid	 lcong48(unsigned short[7]);
137171247Sthompsalong	 lrand48(void);
138170603Sthompsalong	 mrand48(void);
139170603Sthompsalong	 nrand48(unsigned short[3]);
140170603Sthompsaunsigned short
141168793Sthompsa	*seed48(unsigned short[3]);
142168793Sthompsavoid	 srand48(long);
143168793Sthompsa
144168793Sthompsavoid	*alloca(size_t);		/* built-in for gcc */
145171247Sthompsa					/* getcap(3) functions */
146168793Sthompsa__uint32_t
147168793Sthompsa	 arc4random(void);
148168793Sthompsavoid	 arc4random_addrandom(unsigned char *dat, int datlen);
149171247Sthompsavoid	 arc4random_stir(void);
150171247Sthompsa#ifdef __LONG_LONG_SUPPORTED
151171247Sthompsalong long
152168793Sthompsa	 atoll(const char *);
153168793Sthompsa#endif
154171247Sthompsachar	*getbsize(int *, long *);
155171247Sthompsachar	*cgetcap(char *, const char *, int);
156171247Sthompsaint	 cgetclose(void);
157171247Sthompsaint	 cgetent(char **, char **, const char *);
158171247Sthompsaint	 cgetfirst(char **, char **);
159168793Sthompsaint	 cgetmatch(const char *, const char *);
160171247Sthompsaint	 cgetnext(char **, char **);
161171247Sthompsaint	 cgetnum(char *, const char *, long *);
162171247Sthompsaint	 cgetset(const char *);
163168793Sthompsaint	 cgetstr(char *, const char *, char **);
164168793Sthompsaint	 cgetustr(char *, const char *, char **);
165168793Sthompsa
166168793Sthompsaint	 daemon(int, int);
167170603Sthompsachar	*devname(int, int);
168170603Sthompsaint	 getloadavg(double [], int);
169168793Sthompsa__const char *
170168793Sthompsa	 getprogname(void);
171168793Sthompsa
172168793Sthompsaint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
173168793Sthompsachar	*initstate(unsigned long, char *, long);
174168793Sthompsa#ifdef __LONG_LONG_SUPPORTED
175168793Sthompsalong long
176168793Sthompsa	 llabs(long long) __pure2;
177168793Sthompsalldiv_t	 lldiv(long long, long long) __pure2;
178168793Sthompsa#endif
179168793Sthompsaint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
180168793Sthompsaint	 radixsort(const unsigned char **, int, const unsigned char *,
181168793Sthompsa	    unsigned);
182168793Sthompsaint	 sradixsort(const unsigned char **, int, const unsigned char *,
183168793Sthompsa	    unsigned);
184168793Sthompsaint	 rand_r(unsigned *);
185168793Sthompsalong	 random(void);
186168793Sthompsavoid    *reallocf(void *, size_t);
187168793Sthompsachar	*realpath(const char *, char resolved_path[]);
188168793Sthompsavoid	 setprogname(const char *);
189168793Sthompsachar	*setstate(char *);
190168793Sthompsavoid	 sranddev(void);
191168793Sthompsavoid	 srandom(unsigned long);
192168793Sthompsavoid	 srandomdev(void);
193168793Sthompsa#ifdef __LONG_LONG_SUPPORTED
194168793Sthompsalong long
195168793Sthompsa	 strtoll(const char *, char **, int);
196#endif
197__int64_t	 strtoq(const char *, char **, int);
198#ifdef __LONG_LONG_SUPPORTED
199unsigned long long
200	 strtoull(const char *, char **, int);
201#endif
202__uint64_t
203	 strtouq(const char *, char **, int);
204void	 unsetenv(const char *);
205#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
206__END_DECLS
207
208#endif /* !_STDLIB_H_ */
209