stdlib.h revision 102227
1193326Sed/*-
2193326Sed * Copyright (c) 1990, 1993
3193326Sed *	The Regents of the University of California.  All rights reserved.
4193326Sed *
5193326Sed * Redistribution and use in source and binary forms, with or without
6193326Sed * modification, are permitted provided that the following conditions
7193326Sed * are met:
8193326Sed * 1. Redistributions of source code must retain the above copyright
9193326Sed *    notice, this list of conditions and the following disclaimer.
10193326Sed * 2. Redistributions in binary form must reproduce the above copyright
11193326Sed *    notice, this list of conditions and the following disclaimer in the
12193326Sed *    documentation and/or other materials provided with the distribution.
13193326Sed * 3. All advertising materials mentioning features or use of this software
14193326Sed *    must display the following acknowledgement:
15218893Sdim *	This product includes software developed by the University of
16249423Sdim *	California, Berkeley and its contributors.
17249423Sdim * 4. Neither the name of the University nor the names of its contributors
18212904Sdim *    may be used to endorse or promote products derived from this software
19212904Sdim *    without specific prior written permission.
20212904Sdim *
21193326Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22243830Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23193326Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24193326Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25249423Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26249423Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27249423Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28249423Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29249423Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31249423Sdim * SUCH DAMAGE.
32249423Sdim *
33249423Sdim *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34249423Sdim * $FreeBSD: head/include/stdlib.h 102227 2002-08-21 16:20:02Z mike $
35249423Sdim */
36249423Sdim
37193326Sed#ifndef _STDLIB_H_
38193326Sed#define	_STDLIB_H_
39193326Sed
40193326Sed#include <sys/cdefs.h>
41193326Sed#include <sys/_types.h>
42193326Sed
43193326Sed#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
44193326Sed#ifndef _RUNE_T_DECLARED
45193326Sedtypedef	__rune_t	rune_t;
46226633Sdim#define	_RUNE_T_DECLARED
47193326Sed#endif
48198092Srdivacky#endif
49200583Srdivacky
50226633Sdim#ifndef _SIZE_T_DECLARED
51226633Sdimtypedef	__size_t	size_t;
52226633Sdim#define	_SIZE_T_DECLARED
53200583Srdivacky#endif
54226633Sdim
55226633Sdim#ifndef	__cplusplus
56193326Sed#ifndef _WCHAR_T_DECLARED
57193326Sedtypedef	__wchar_t	wchar_t;
58193326Sed#define	_WCHAR_T_DECLARED
59218893Sdim#endif
60221345Sdim#endif
61226633Sdim
62226633Sdimtypedef struct {
63218893Sdim	int quot;		/* quotient */
64218893Sdim	int rem;		/* remainder */
65221345Sdim} div_t;
66234353Sdim
67218893Sdimtypedef struct {
68193326Sed	long quot;		/* quotient */
69234353Sdim	long rem;		/* remainder */
70193326Sed} ldiv_t;
71193326Sed
72193326Sed#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
73226633Sdim#ifdef __LONG_LONG_SUPPORTED
74226633Sdim/* LONGLONG */
75193326Sedtypedef struct {
76226633Sdim	long long quot;
77226633Sdim	long long rem;
78193326Sed} lldiv_t;
79226633Sdim#endif
80226633Sdim#endif
81249423Sdim
82234353Sdim#ifndef NULL
83234353Sdim#define	NULL	0
84234353Sdim#endif
85234353Sdim
86234353Sdim#define	EXIT_FAILURE	1
87193326Sed#define	EXIT_SUCCESS	0
88193326Sed
89193326Sed#define	RAND_MAX	0x7fffffff
90226633Sdim
91226633Sdimextern int __mb_cur_max;
92193326Sed#define	MB_CUR_MAX	__mb_cur_max
93226633Sdim
94193326Sed__BEGIN_DECLS
95193326Sedvoid	 abort(void) __dead2;
96193326Sedint	 abs(int) __pure2;
97198092Srdivackyint	 atexit(void (*)(void));
98193326Seddouble	 atof(const char *);
99198092Srdivackyint	 atoi(const char *);
100226633Sdimlong	 atol(const char *);
101226633Sdimvoid	*bsearch(const void *, const void *, size_t,
102193326Sed	    size_t, int (*)(const void *, const void *));
103226633Sdimvoid	*calloc(size_t, size_t);
104226633Sdimdiv_t	 div(int, int) __pure2;
105198092Srdivackyvoid	 exit(int) __dead2;
106199482Srdivackyvoid	 free(void *);
107193326Sedchar	*getenv(const char *);
108249423Sdimlong	 labs(long) __pure2;
109193326Sedldiv_t	 ldiv(long, long) __pure2;
110193326Sedvoid	*malloc(size_t);
111193326Sedvoid	 qsort(void *, size_t, size_t,
112226633Sdim	    int (*)(const void *, const void *));
113193326Sedint	 rand(void);
114193326Sedvoid	*realloc(void *, size_t);
115199482Srdivackyvoid	 srand(unsigned);
116193326Seddouble	 strtod(const char *__restrict, char **__restrict);
117198092Srdivackylong	 strtol(const char *__restrict, char **__restrict, int);
118193326Sedunsigned long
119193326Sed	 strtoul(const char *__restrict, char **__restrict, int);
120198092Srdivackyint	 system(const char *);
121193326Sed
122193326Sedint	 mblen(const char *, size_t);
123198092Srdivackysize_t	 mbstowcs(wchar_t *, const char *, size_t);
124193326Sedint	 wctomb(char *, wchar_t);
125193326Sedint	 mbtowc(wchar_t *, const char *, size_t);
126226633Sdimsize_t	 wcstombs(char *, const wchar_t *, size_t);
127198092Srdivacky
128199482Srdivacky#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
129199482Srdivackyextern const char *_malloc_options;
130199482Srdivackyextern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4);
131193326Sed
132193326Sedint	 putenv(const char *);
133234353Sdimint	 setenv(const char *, const char *, int);
134234353Sdim
135234353Sdimdouble	 drand48(void);
136234353Sdimdouble	 erand48(unsigned short[3]);
137234353Sdimlong	 jrand48(unsigned short[3]);
138234353Sdimvoid	 lcong48(unsigned short[7]);
139234353Sdimlong	 lrand48(void);
140234353Sdimlong	 mrand48(void);
141234353Sdimlong	 nrand48(unsigned short[3]);
142234353Sdimunsigned short
143234353Sdim	*seed48(unsigned short[3]);
144234353Sdimvoid	 srand48(long);
145234353Sdim
146234353Sdimvoid	*alloca(size_t);		/* built-in for gcc */
147234353Sdim					/* getcap(3) functions */
148234353Sdim__uint32_t
149234353Sdim	 arc4random(void);
150234353Sdimvoid	 arc4random_addrandom(unsigned char *dat, int datlen);
151234353Sdimvoid	 arc4random_stir(void);
152193326Sed#ifdef __LONG_LONG_SUPPORTED
153193326Sed/* LONGLONG */
154193326Sedlong long
155193326Sed	 atoll(const char *);
156193326Sed#endif
157193326Sedchar	*getbsize(int *, long *);
158198092Srdivackychar	*cgetcap(char *, const char *, int);
159193326Sedint	 cgetclose(void);
160198092Srdivackyint	 cgetent(char **, char **, const char *);
161193326Sedint	 cgetfirst(char **, char **);
162193326Sedint	 cgetmatch(const char *, const char *);
163193326Sedint	 cgetnext(char **, char **);
164193326Sedint	 cgetnum(char *, const char *, long *);
165198092Srdivackyint	 cgetset(const char *);
166193326Sedint	 cgetstr(char *, const char *, char **);
167193326Sedint	 cgetustr(char *, const char *, char **);
168193326Sed
169193326Sedint	 daemon(int, int);
170193326Sedchar	*devname(int, int);
171193326Sedint	 getloadavg(double [], int);
172193326Sed__const char *
173193326Sed	 getprogname(void);
174193326Sed
175193326Sedint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
176193326Sedchar	*initstate(unsigned long, char *, long);
177193326Sed#ifdef __LONG_LONG_SUPPORTED
178193326Sed/* LONGLONG */
179234353Sdimlong long
180193326Sed	 llabs(long long) __pure2;
181234353Sdimlldiv_t	 lldiv(long long, long long) __pure2;
182218893Sdim#endif
183193326Sedint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
184193326Sedint	 radixsort(const unsigned char **, int, const unsigned char *,
185234353Sdim	    unsigned);
186193326Sedint	 sradixsort(const unsigned char **, int, const unsigned char *,
187198092Srdivacky	    unsigned);
188199512Srdivackyint	 rand_r(unsigned *);
189199512Srdivackylong	 random(void);
190210299Sedvoid    *reallocf(void *, size_t);
191226633Sdimchar	*realpath(const char *, char resolved_path[]);
192226633Sdimvoid	 setprogname(const char *);
193199512Srdivackychar	*setstate(char *);
194199512Srdivackyvoid	 sranddev(void);
195249423Sdimvoid	 srandom(unsigned long);
196249423Sdimvoid	 srandomdev(void);
197193326Sed#ifdef __LONG_LONG_SUPPORTED
198193326Sed/* LONGLONG */
199212904Sdimlong long
200193326Sed	 strtoll(const char *__restrict, char **__restrict, int);
201199482Srdivacky#endif
202193326Sed__int64_t	 strtoq(const char *, char **, int);
203193326Sed#ifdef __LONG_LONG_SUPPORTED
204193326Sed/* LONGLONG */
205207619Srdivackyunsigned long long
206207619Srdivacky	 strtoull(const char *__restrict, char **__restrict, int);
207226633Sdim#endif
208226633Sdim__uint64_t
209226633Sdim	 strtouq(const char *, char **, int);
210226633Sdimvoid	 unsetenv(const char *);
211226633Sdim#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
212193326Sed__END_DECLS
213199512Srdivacky
214210299Sed#endif /* !_STDLIB_H_ */
215226633Sdim