stdlib.h revision 1.67
1/*	$NetBSD: stdlib.h,v 1.67 2004/05/27 02:58:14 christos Exp $	*/
2
3/*-
4 * Copyright (c) 1990, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
32 */
33
34#ifndef _STDLIB_H_
35#define _STDLIB_H_
36
37#include <sys/cdefs.h>
38#include <sys/featuretest.h>
39
40#if defined(_NETBSD_SOURCE)
41#include <sys/types.h>		/* for quad_t, etc. */
42#endif
43
44#include <machine/ansi.h>
45
46#ifdef	_BSD_SIZE_T_
47typedef	_BSD_SIZE_T_	size_t;
48#undef	_BSD_SIZE_T_
49#endif
50
51#ifdef	_BSD_WCHAR_T_
52typedef	_BSD_WCHAR_T_	wchar_t;
53#undef	_BSD_WCHAR_T_
54#endif
55
56typedef struct {
57	int quot;		/* quotient */
58	int rem;		/* remainder */
59} div_t;
60
61typedef struct {
62	long quot;		/* quotient */
63	long rem;		/* remainder */
64} ldiv_t;
65
66#if !defined(_ANSI_SOURCE) && \
67    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
68     defined(_NETBSD_SOURCE))
69typedef struct {
70	/* LONGLONG */
71	long long int quot;	/* quotient */
72	/* LONGLONG */
73	long long int rem;	/* remainder */
74} lldiv_t;
75#endif
76
77#if defined(_NETBSD_SOURCE)
78typedef struct {
79	quad_t quot;		/* quotient */
80	quad_t rem;		/* remainder */
81} qdiv_t;
82#endif
83
84
85#include <sys/null.h>
86
87#define	EXIT_FAILURE	1
88#define	EXIT_SUCCESS	0
89
90#define	RAND_MAX	0x7fffffff
91
92extern size_t __mb_cur_max;
93#define	MB_CUR_MAX	__mb_cur_max
94
95__BEGIN_DECLS
96__dead	 void _Exit __P((int)) __attribute__((__noreturn__));
97__dead	 void abort __P((void)) __attribute__((__noreturn__));
98__pure	 int abs __P((int));
99int	 atexit __P((void (*)(void)));
100double	 atof __P((const char *));
101int	 atoi __P((const char *));
102long	 atol __P((const char *));
103#ifndef __BSEARCH_DECLARED
104#define __BSEARCH_DECLARED
105/* also in search.h */
106void	*bsearch __P((const void *, const void *, size_t, size_t,
107    int (*)(const void *, const void *)));
108#endif /* __BSEARCH_DECLARED */
109void	*calloc __P((size_t, size_t));
110div_t	 div __P((int, int));
111__dead	 void exit __P((int)) __attribute__((__noreturn__));
112void	 free __P((void *));
113__aconst char *getenv __P((const char *));
114__pure long
115	 labs __P((long));
116ldiv_t	 ldiv __P((long, long));
117void	*malloc __P((size_t));
118void	 qsort __P((void *, size_t, size_t,
119	    int (*)(const void *, const void *)));
120int	 rand __P((void));
121void	*realloc __P((void *, size_t));
122void	 srand __P((unsigned));
123double	 strtod __P((const char * __restrict, char ** __restrict));
124long	 strtol __P((const char * __restrict, char ** __restrict, int));
125unsigned long
126	 strtoul __P((const char * __restrict, char ** __restrict, int));
127int	 system __P((const char *));
128
129/* These are currently just stubs. */
130int	 mblen __P((const char *, size_t));
131size_t	 mbstowcs __P((wchar_t * __restrict, const char * __restrict, size_t));
132int	 wctomb __P((char *, wchar_t));
133int	 mbtowc __P((wchar_t * __restrict, const char * __restrict, size_t));
134size_t	 wcstombs __P((char * __restrict, const wchar_t * __restrict, size_t));
135
136#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
137    defined(_NETBSD_SOURCE)
138
139
140/*
141 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
142 */
143#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
144    defined(_REENTRANT) || defined(_NETBSD_SOURCE)
145int	 rand_r __P((unsigned int *));
146#endif
147
148
149/*
150 * X/Open Portability Guide >= Issue 4
151 */
152#if (_XOPEN_SOURCE - 0) >= 4 || defined(_NETBSD_SOURCE)
153double	 drand48 __P((void));
154double	 erand48 __P((unsigned short[3]));
155long	 jrand48 __P((unsigned short[3]));
156void	 lcong48 __P((unsigned short[7]));
157long	 lrand48 __P((void));
158long	 mrand48 __P((void));
159long	 nrand48 __P((unsigned short[3]));
160unsigned short *
161	 seed48 __P((unsigned short[3]));
162void	 srand48 __P((long));
163
164int	 putenv __P((const char *));
165#endif
166
167
168/*
169 * X/Open Portability Guide >= Issue 4 Version 2
170 */
171#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
172    (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
173long	 a64l __P((const char *));
174char	*l64a __P((long));
175
176char	*initstate __P((unsigned long, char *, size_t));
177long	 random __P((void));
178char	*setstate __P((char *));
179void	 srandom __P((unsigned long));
180
181char	*mkdtemp __P((char *));
182int	 mkstemp __P((char *));
183#ifndef __AUDIT__
184char	*mktemp __P((char *));
185#endif
186
187int	 setkey __P((const char *));
188
189char	*realpath __P((const char *, char *));
190
191int	 ttyslot __P((void));
192
193void	*valloc __P((size_t));		/* obsoleted by malloc() */
194
195int	 grantpt __P((int));
196int	 unlockpt __P((int));
197char	*ptsname __P((int));
198#endif
199
200/*
201 * ISO C99
202 */
203#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
204    defined(_NETBSD_SOURCE)
205/* LONGLONG */
206long long int	atoll __P((const char *));
207/* LONGLONG */
208long long int	llabs __P((long long int));
209/* LONGLONG */
210lldiv_t		lldiv __P((long long int, long long int));
211/* LONGLONG */
212long long int	strtoll __P((const char * __restrict, char ** __restrict, int));
213/* LONGLONG */
214unsigned long long int
215		strtoull __P((const char * __restrict, char ** __restrict,
216		    int));
217#endif
218
219/*
220 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
221 */
222#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \
223    defined(_NETBSD_SOURCE)
224int	 setenv __P((const char *, const char *, int));
225#ifdef __LIBC12_SOURCE__
226void	 unsetenv __P((const char *));
227int	 __unsetenv13 __P((const char *));
228#else
229int	 unsetenv __P((const char *))		__RENAME(__unsetenv13);
230#endif
231
232int	 posix_openpt __P((int));
233#endif
234
235/*
236 * Implementation-defined extensions
237 */
238#if defined(_NETBSD_SOURCE)
239#if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2)
240void	*alloca __P((int));     /* built-in for gcc */
241#else
242void	*alloca __P((size_t));
243#endif /* __GNUC__ */
244
245u_int32_t arc4random __P((void));
246void	 arc4random_stir __P((void));
247void	 arc4random_addrandom __P((u_char *, int));
248char	*getbsize __P((int *, long *));
249char	*cgetcap __P((char *, const char *, int));
250int	 cgetclose __P((void));
251int	 cgetent __P((char **, const char * const *, const char *));
252int	 cgetfirst __P((char **, const char * const *));
253int	 cgetmatch __P((const char *, const char *));
254int	 cgetnext __P((char **, const char * const *));
255int	 cgetnum __P((char *, const char *, long *));
256int	 cgetset __P((const char *));
257int	 cgetstr __P((char *, const char *, char **));
258int	 cgetustr __P((char *, const char *, char **));
259
260int	 daemon __P((int, int));
261__aconst char *devname __P((dev_t, mode_t));
262int	 getloadavg __P((double [], int));
263
264void	 cfree __P((void *));
265
266int	 heapsort __P((void *, size_t, size_t,
267	    int (*)(const void *, const void *)));
268int	 mergesort __P((void *, size_t, size_t,
269	    int (*)(const void *, const void *)));
270int	 radixsort __P((const unsigned char **, int, const unsigned char *,
271	    unsigned));
272int	 sradixsort __P((const unsigned char **, int, const unsigned char *,
273	    unsigned));
274
275void	 setproctitle __P((const char *, ...))
276	    __attribute__((__format__(__printf__, 1, 2)));
277const char *getprogname __P((void)) __attribute__((__const__));
278void	setprogname __P((const char *));
279
280quad_t	 qabs __P((quad_t));
281quad_t	 strtoq __P((const char * __restrict, char ** __restrict, int));
282u_quad_t strtouq __P((const char * __restrict, char ** __restrict, int));
283
284	/* LONGLONG */
285long long strsuftoll(const char *, const char *, long long, long long);
286	/* LONGLONG */
287long long strsuftollx(const char *, const char *, long long, long long,
288	    		char *, size_t);
289
290int	 l64a_r __P((long, char *, int));
291
292size_t	shquote __P((const char *, char *, size_t));
293size_t	shquotev __P((int, char * const *, char *, size_t));
294#endif /* _NETBSD_SOURCE */
295#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
296
297#if defined(_NETBSD_SOURCE)
298qdiv_t	 qdiv __P((quad_t, quad_t));
299#endif
300__END_DECLS
301
302#endif /* !_STDLIB_H_ */
303