stdlib.h revision 1.64
1/*	$OpenBSD: stdlib.h,v 1.64 2015/02/08 02:58:50 tedu Exp $	*/
2/*	$NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $	*/
3
4/*-
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 *	@(#)stdlib.h	5.13 (Berkeley) 6/4/91
33 */
34
35#ifndef _STDLIB_H_
36#define _STDLIB_H_
37
38#include <sys/cdefs.h>
39#include <machine/_types.h>
40#if __BSD_VISIBLE	/* for quad_t, etc. (XXX - use protected types) */
41#include <sys/types.h>
42#endif
43
44#ifndef	_SIZE_T_DEFINED_
45#define	_SIZE_T_DEFINED_
46typedef	__size_t	size_t;
47#endif
48
49/* in C++, wchar_t is a built-in type */
50#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus)
51#define _WCHAR_T_DEFINED_
52typedef	__wchar_t	wchar_t;
53#endif
54
55typedef struct {
56	int quot;		/* quotient */
57	int rem;		/* remainder */
58} div_t;
59
60typedef struct {
61	long quot;		/* quotient */
62	long rem;		/* remainder */
63} ldiv_t;
64
65#if __ISO_C_VISIBLE >= 1999
66typedef struct {
67	long long quot;		/* quotient */
68	long long rem;		/* remainder */
69} lldiv_t;
70#endif
71
72#if __BSD_VISIBLE
73typedef struct {
74	quad_t quot;		/* quotient */
75	quad_t rem;		/* remainder */
76} qdiv_t;
77#endif
78
79
80#ifndef	NULL
81#ifdef 	__GNUG__
82#define NULL	__null
83#elif defined(__cplusplus)
84#define	NULL	0L
85#else
86#define	NULL	((void *)0)
87#endif
88#endif
89
90#define	EXIT_FAILURE	1
91#define	EXIT_SUCCESS	0
92
93#define	RAND_MAX	0x7fffffff
94
95extern size_t	__mb_cur_max;
96#define	MB_CUR_MAX	__mb_cur_max
97
98#include <sys/cdefs.h>
99
100/*
101 * Some header files may define an abs macro.
102 * If defined, undef it to prevent a syntax error and issue a warning.
103 */
104#ifdef abs
105#undef abs
106#warning abs macro collides with abs() prototype, undefining
107#endif
108
109__BEGIN_DECLS
110__dead void	 abort(void);
111int	 abs(int);
112int	 atexit(void (*)(void));
113double	 atof(const char *);
114int	 atoi(const char *);
115long	 atol(const char *);
116void	*bsearch(const void *, const void *, size_t, size_t,
117	    int (*)(const void *, const void *));
118void	*calloc(size_t, size_t);
119div_t	 div(int, int);
120__dead void	 exit(int);
121__dead void	 _Exit(int);
122void	 free(void *);
123char	*getenv(const char *);
124long	 labs(long);
125ldiv_t	 ldiv(long, long);
126void	*malloc(size_t);
127#if __BSD_VISIBLE
128void	*reallocarray(void *, size_t, size_t);
129#endif /* __BSD_VISIBLE */
130void	 qsort(void *, size_t, size_t, int (*)(const void *, const void *));
131int	 rand(void);
132void	*realloc(void *, size_t);
133void	 srand(unsigned);
134void	 srand_deterministic(unsigned);
135double	 strtod(const char *__restrict, char **__restrict);
136float	 strtof(const char *__restrict, char **__restrict);
137long	 strtol(const char *__restrict, char **__restrict, int);
138long double
139	 strtold(const char *__restrict, char **__restrict);
140unsigned long
141	 strtoul(const char *__restrict, char **__restrict, int);
142int	 system(const char *);
143
144/* these are currently just stubs */
145int	 mblen(const char *, size_t);
146size_t	 mbstowcs(wchar_t *, const char *, size_t);
147int	 wctomb(char *, wchar_t);
148int	 mbtowc(wchar_t *, const char *, size_t);
149size_t	 wcstombs(char *, const wchar_t *, size_t);
150
151/*
152 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
153 */
154#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || defined(_REENTRANT)
155int	 rand_r(unsigned int *);
156#endif
157
158#if __BSD_VISIBLE || __XPG_VISIBLE >= 400
159double	 drand48(void);
160double	 erand48(unsigned short[3]);
161long	 jrand48(unsigned short[3]);
162void	 lcong48(unsigned short[7]);
163void	 lcong48_deterministic(unsigned short[7]);
164long	 lrand48(void);
165long	 mrand48(void);
166long	 nrand48(unsigned short[3]);
167unsigned short *seed48(unsigned short[3]);
168unsigned short *seed48_deterministic(unsigned short[3]);
169void	 srand48(long);
170void	 srand48_deterministic(long);
171
172int	 putenv(char *);
173#endif
174
175/*
176 * XSI functions marked LEGACY in IEEE Std 1003.1-2001 (POSIX) and
177 * removed in IEEE Std 1003.1-2008
178 */
179#if __BSD_VISIBLE || __XPG_VISIBLE < 700
180char	*ecvt(double, int, int *, int *);
181char	*fcvt(double, int, int *, int *);
182char	*gcvt(double, int, char *);
183#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
184char	*mktemp(char *);
185#endif
186#endif	/* __BSD_VISIBLE || __XPG_VISIBLE < 700 */
187
188#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
189long	 a64l(const char *);
190char	*l64a(long);
191
192char	*initstate(unsigned int, char *, size_t)
193		__attribute__((__bounded__ (__string__,2,3)));
194long	 random(void);
195char	*setstate(char *);
196void	 srandom(unsigned int);
197void	 srandom_deterministic(unsigned int);
198
199char	*realpath(const char *, char *)
200		__attribute__((__bounded__ (__minbytes__,2,1024)));
201
202/*
203 * XSI functions marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001
204 */
205#if __BSD_VISIBLE || __XPG_VISIBLE < 600
206int	 ttyslot(void);
207void	*valloc(size_t);		/* obsoleted by malloc() */
208#endif
209#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
210
211/*
212 * 4.4BSD, then XSI in XPG4.2, then added to POSIX base in IEEE Std 1003.1-2008
213 */
214#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
215int	 mkstemp(char *);
216#endif
217
218/*
219 * ISO C99
220 */
221#if __ISO_C_VISIBLE >= 1999
222long long
223	 atoll(const char *);
224long long
225	 llabs(long long);
226lldiv_t
227	 lldiv(long long, long long);
228long long
229	 strtoll(const char *__restrict, char **__restrict, int);
230unsigned long long
231	 strtoull(const char *__restrict, char **__restrict, int);
232#endif
233
234/*
235 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
236 */
237#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
238int	 posix_memalign(void **, size_t, size_t);
239int	 setenv(const char *, const char *, int);
240int	 unsetenv(const char *);
241#endif
242#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200112
243char	*ptsname(int);
244int	 grantpt(int);
245int	 unlockpt(int);
246#endif
247#if __POSIX_VISIBLE >= 200112
248int	 posix_openpt(int);
249#endif
250
251/*
252 * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX)
253 */
254#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
255char	*mkdtemp(char *);
256#endif
257
258#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
259int     getsubopt(char **, char * const *, char **);
260#endif
261
262/*
263 * The Open Group Base Specifications, post-Issue 7
264 */
265#if __BSD_VISIBLE
266int	mkostemp(char *, int);
267#endif
268
269#if __BSD_VISIBLE
270#define alloca(n) __builtin_alloca(n)
271
272char	*getbsize(int *, long *);
273char	*cgetcap(char *, const char *, int);
274int	 cgetclose(void);
275int	 cgetent(char **, char **, const char *);
276int	 cgetfirst(char **, char **);
277int	 cgetmatch(char *, const char *);
278int	 cgetnext(char **, char **);
279int	 cgetnum(char *, const char *, long *);
280int	 cgetset(const char *);
281int	 cgetusedb(int);
282int	 cgetstr(char *, const char *, char **);
283int	 cgetustr(char *, const char *, char **);
284
285int	 daemon(int, int);
286char	*devname(int, mode_t);
287int	 getloadavg(double [], int);
288
289const char *
290	getprogname(void);
291void	setprogname(const char *);
292
293extern	 char *suboptarg;		/* getsubopt(3) external variable */
294
295int	 mkstemps(char *, int);
296int	 mkostemps(char *, int, int);
297
298int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
299int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
300int	 radixsort(const unsigned char **, int, const unsigned char *,
301	    unsigned);
302int	 sradixsort(const unsigned char **, int, const unsigned char *,
303	    unsigned);
304
305void	 srandomdev(void);
306long long
307	 strtonum(const char *, long long, long long, const char **);
308
309void	 setproctitle(const char *, ...)
310	__attribute__((__format__ (__printf__, 1, 2)));
311
312quad_t	 qabs(quad_t);
313qdiv_t	 qdiv(quad_t, quad_t);
314quad_t	 strtoq(const char *__restrict, char **__restrict, int);
315u_quad_t strtouq(const char *__restrict, char **__restrict, int);
316
317uint32_t arc4random(void);
318uint32_t arc4random_uniform(uint32_t);
319void arc4random_buf(void *, size_t)
320	__attribute__((__bounded__ (__string__,1,2)));
321
322#endif /* __BSD_VISIBLE */
323
324__END_DECLS
325
326#endif /* _STDLIB_H_ */
327