xref: /freebsd/include/stdlib.h (revision c4f6a2a9e1b1879b618c436ab4f56ff75c73a0f5)
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$
35  */
36 
37 #ifndef _STDLIB_H_
38 #define	_STDLIB_H_
39 
40 #include <sys/cdefs.h>
41 #include <sys/_types.h>
42 
43 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
44 #ifndef _RUNE_T_DECLARED
45 typedef	__rune_t	rune_t;
46 #define	_RUNE_T_DECLARED
47 #endif
48 #endif
49 
50 #ifndef _SIZE_T_DECLARED
51 typedef	__size_t	size_t;
52 #define	_SIZE_T_DECLARED
53 #endif
54 
55 #ifndef	__cplusplus
56 #ifndef _WCHAR_T_DECLARED
57 typedef	__wchar_t	wchar_t;
58 #define	_WCHAR_T_DECLARED
59 #endif
60 #endif
61 
62 typedef struct {
63 	int quot;		/* quotient */
64 	int rem;		/* remainder */
65 } div_t;
66 
67 typedef struct {
68 	long quot;		/* quotient */
69 	long rem;		/* remainder */
70 } ldiv_t;
71 
72 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
73 #ifdef __LONG_LONG_SUPPORTED
74 /* LONGLONG */
75 typedef struct {
76 	long long quot;
77 	long long rem;
78 } lldiv_t;
79 #endif
80 #endif
81 
82 #ifndef NULL
83 #define	NULL	0
84 #endif
85 
86 #define	EXIT_FAILURE	1
87 #define	EXIT_SUCCESS	0
88 
89 #define	RAND_MAX	0x7fffffff
90 
91 extern int __mb_cur_max;
92 #define	MB_CUR_MAX	__mb_cur_max
93 
94 __BEGIN_DECLS
95 void	 abort(void) __dead2;
96 int	 abs(int) __pure2;
97 int	 atexit(void (*)(void));
98 double	 atof(const char *);
99 int	 atoi(const char *);
100 long	 atol(const char *);
101 void	*bsearch(const void *, const void *, size_t,
102 	    size_t, int (*)(const void *, const void *));
103 void	*calloc(size_t, size_t);
104 div_t	 div(int, int) __pure2;
105 void	 exit(int) __dead2;
106 void	 free(void *);
107 char	*getenv(const char *);
108 long	 labs(long) __pure2;
109 ldiv_t	 ldiv(long, long) __pure2;
110 void	*malloc(size_t);
111 void	 qsort(void *, size_t, size_t,
112 	    int (*)(const void *, const void *));
113 int	 rand(void);
114 void	*realloc(void *, size_t);
115 void	 srand(unsigned);
116 double	 strtod(const char *__restrict, char **__restrict);
117 long	 strtol(const char *__restrict, char **__restrict, int);
118 unsigned long
119 	 strtoul(const char *__restrict, char **__restrict, int);
120 int	 system(const char *);
121 
122 int	 mblen(const char *, size_t);
123 size_t	 mbstowcs(wchar_t *, const char *, size_t);
124 int	 wctomb(char *, wchar_t);
125 int	 mbtowc(wchar_t *, const char *, size_t);
126 size_t	 wcstombs(char *, const wchar_t *, size_t);
127 
128 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
129 extern const char *_malloc_options;
130 extern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4);
131 
132 int	 putenv(const char *);
133 int	 setenv(const char *, const char *, int);
134 
135 double	 drand48(void);
136 double	 erand48(unsigned short[3]);
137 long	 jrand48(unsigned short[3]);
138 void	 lcong48(unsigned short[7]);
139 long	 lrand48(void);
140 long	 mrand48(void);
141 long	 nrand48(unsigned short[3]);
142 unsigned short
143 	*seed48(unsigned short[3]);
144 void	 srand48(long);
145 
146 void	*alloca(size_t);		/* built-in for gcc */
147 					/* getcap(3) functions */
148 __uint32_t
149 	 arc4random(void);
150 void	 arc4random_addrandom(unsigned char *dat, int datlen);
151 void	 arc4random_stir(void);
152 #ifdef __LONG_LONG_SUPPORTED
153 /* LONGLONG */
154 long long
155 	 atoll(const char *);
156 #endif
157 char	*getbsize(int *, long *);
158 char	*cgetcap(char *, const char *, int);
159 int	 cgetclose(void);
160 int	 cgetent(char **, char **, const char *);
161 int	 cgetfirst(char **, char **);
162 int	 cgetmatch(const char *, const char *);
163 int	 cgetnext(char **, char **);
164 int	 cgetnum(char *, const char *, long *);
165 int	 cgetset(const char *);
166 int	 cgetstr(char *, const char *, char **);
167 int	 cgetustr(char *, const char *, char **);
168 
169 int	 daemon(int, int);
170 char	*devname(int, int);
171 int	 getloadavg(double [], int);
172 __const char *
173 	 getprogname(void);
174 
175 int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
176 char	*initstate(unsigned long, char *, long);
177 #ifdef __LONG_LONG_SUPPORTED
178 /* LONGLONG */
179 long long
180 	 llabs(long long) __pure2;
181 lldiv_t	 lldiv(long long, long long) __pure2;
182 #endif
183 int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
184 int	 radixsort(const unsigned char **, int, const unsigned char *,
185 	    unsigned);
186 int	 sradixsort(const unsigned char **, int, const unsigned char *,
187 	    unsigned);
188 int	 rand_r(unsigned *);
189 long	 random(void);
190 void    *reallocf(void *, size_t);
191 char	*realpath(const char *, char resolved_path[]);
192 void	 setprogname(const char *);
193 char	*setstate(char *);
194 void	 sranddev(void);
195 void	 srandom(unsigned long);
196 void	 srandomdev(void);
197 #ifdef __LONG_LONG_SUPPORTED
198 /* LONGLONG */
199 long long
200 	 strtoll(const char *__restrict, char **__restrict, int);
201 #endif
202 __int64_t	 strtoq(const char *, char **, int);
203 #ifdef __LONG_LONG_SUPPORTED
204 /* LONGLONG */
205 unsigned long long
206 	 strtoull(const char *__restrict, char **__restrict, int);
207 #endif
208 __uint64_t
209 	 strtouq(const char *, char **, int);
210 void	 unsetenv(const char *);
211 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
212 __END_DECLS
213 
214 #endif /* !_STDLIB_H_ */
215