xref: /freebsd/include/stdlib.h (revision 7a4a63270ffd4cf0deae379b3ad32f57ea3c3e9d)
159deaec5SRodney W. Grimes /*-
259deaec5SRodney W. Grimes  * Copyright (c) 1990, 1993
359deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
459deaec5SRodney W. Grimes  *
559deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
659deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
759deaec5SRodney W. Grimes  * are met:
859deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
959deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1059deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1259deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
1359deaec5SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
1459deaec5SRodney W. Grimes  *    must display the following acknowledgement:
1559deaec5SRodney W. Grimes  *	This product includes software developed by the University of
1659deaec5SRodney W. Grimes  *	California, Berkeley and its contributors.
1759deaec5SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
1859deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1959deaec5SRodney W. Grimes  *    without specific prior written permission.
2059deaec5SRodney W. Grimes  *
2159deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2259deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2359deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2459deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2559deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2659deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2759deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2859deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2959deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3059deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3159deaec5SRodney W. Grimes  * SUCH DAMAGE.
3259deaec5SRodney W. Grimes  *
33c59376afSPeter Wemm  *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
34dea750aeSBruce Evans  * $FreeBSD$
3559deaec5SRodney W. Grimes  */
3659deaec5SRodney W. Grimes 
3759deaec5SRodney W. Grimes #ifndef _STDLIB_H_
3859deaec5SRodney W. Grimes #define	_STDLIB_H_
3959deaec5SRodney W. Grimes 
4085b46962SBruce Evans #include <sys/cdefs.h>
4185b46962SBruce Evans 
4259deaec5SRodney W. Grimes #include <machine/ansi.h>
4359deaec5SRodney W. Grimes 
44cdd84b02SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
45cdd84b02SBruce Evans #ifdef	_BSD_RUNE_T_
46cdd84b02SBruce Evans typedef	_BSD_RUNE_T_	rune_t;
47cdd84b02SBruce Evans #undef	_BSD_RUNE_T_
48cdd84b02SBruce Evans #endif
49cdd84b02SBruce Evans #endif
50cdd84b02SBruce Evans 
5159deaec5SRodney W. Grimes #ifdef	_BSD_SIZE_T_
5259deaec5SRodney W. Grimes typedef	_BSD_SIZE_T_	size_t;
5359deaec5SRodney W. Grimes #undef	_BSD_SIZE_T_
5459deaec5SRodney W. Grimes #endif
5559deaec5SRodney W. Grimes 
5659deaec5SRodney W. Grimes #ifdef	_BSD_WCHAR_T_
5759deaec5SRodney W. Grimes typedef	_BSD_WCHAR_T_	wchar_t;
5859deaec5SRodney W. Grimes #undef	_BSD_WCHAR_T_
5959deaec5SRodney W. Grimes #endif
6059deaec5SRodney W. Grimes 
6159deaec5SRodney W. Grimes typedef struct {
6259deaec5SRodney W. Grimes 	int quot;		/* quotient */
6359deaec5SRodney W. Grimes 	int rem;		/* remainder */
6459deaec5SRodney W. Grimes } div_t;
6559deaec5SRodney W. Grimes 
6659deaec5SRodney W. Grimes typedef struct {
6759deaec5SRodney W. Grimes 	long quot;		/* quotient */
6859deaec5SRodney W. Grimes 	long rem;		/* remainder */
6959deaec5SRodney W. Grimes } ldiv_t;
7059deaec5SRodney W. Grimes 
717a4a6327SMike Barcroft #ifdef __LONG_LONG_SUPPORTED
727a4a6327SMike Barcroft typedef struct {
737a4a6327SMike Barcroft 	long long quot;
747a4a6327SMike Barcroft 	long long rem;
757a4a6327SMike Barcroft } lldiv_t;
767a4a6327SMike Barcroft #endif
777a4a6327SMike Barcroft 
7859deaec5SRodney W. Grimes #ifndef NULL
7959deaec5SRodney W. Grimes #define	NULL	0
8059deaec5SRodney W. Grimes #endif
8159deaec5SRodney W. Grimes 
8259deaec5SRodney W. Grimes #define	EXIT_FAILURE	1
8359deaec5SRodney W. Grimes #define	EXIT_SUCCESS	0
8459deaec5SRodney W. Grimes 
8559deaec5SRodney W. Grimes #define	RAND_MAX	0x7fffffff
8659deaec5SRodney W. Grimes 
8759deaec5SRodney W. Grimes extern int __mb_cur_max;
8859deaec5SRodney W. Grimes #define	MB_CUR_MAX	__mb_cur_max
8959deaec5SRodney W. Grimes 
9059deaec5SRodney W. Grimes __BEGIN_DECLS
91eaa86f9dSBruce Evans void	 abort __P((void)) __dead2;
92eaa86f9dSBruce Evans int	 abs __P((int)) __pure2;
9359deaec5SRodney W. Grimes int	 atexit __P((void (*)(void)));
9459deaec5SRodney W. Grimes double	 atof __P((const char *));
9559deaec5SRodney W. Grimes int	 atoi __P((const char *));
9659deaec5SRodney W. Grimes long	 atol __P((const char *));
9759deaec5SRodney W. Grimes void	*bsearch __P((const void *, const void *, size_t,
9859deaec5SRodney W. Grimes 	    size_t, int (*)(const void *, const void *)));
9959deaec5SRodney W. Grimes void	*calloc __P((size_t, size_t));
100eaa86f9dSBruce Evans div_t	 div __P((int, int)) __pure2;
101eaa86f9dSBruce Evans void	 exit __P((int)) __dead2;
10259deaec5SRodney W. Grimes void	 free __P((void *));
10359deaec5SRodney W. Grimes char	*getenv __P((const char *));
104eaa86f9dSBruce Evans long	 labs __P((long)) __pure2;
105eaa86f9dSBruce Evans ldiv_t	 ldiv __P((long, long)) __pure2;
10659deaec5SRodney W. Grimes void	*malloc __P((size_t));
10759deaec5SRodney W. Grimes void	 qsort __P((void *, size_t, size_t,
10859deaec5SRodney W. Grimes 	    int (*)(const void *, const void *)));
10959deaec5SRodney W. Grimes int	 rand __P((void));
11059deaec5SRodney W. Grimes void	*realloc __P((void *, size_t));
11159deaec5SRodney W. Grimes void	 srand __P((unsigned));
11259deaec5SRodney W. Grimes double	 strtod __P((const char *, char **));
11359deaec5SRodney W. Grimes long	 strtol __P((const char *, char **, int));
1144c0440cbSDavid E. O'Brien long long
1154c0440cbSDavid E. O'Brien 	 strtoll __P((const char *, char **, int));
11659deaec5SRodney W. Grimes unsigned long
11759deaec5SRodney W. Grimes 	 strtoul __P((const char *, char **, int));
1184c0440cbSDavid E. O'Brien unsigned long long
1194c0440cbSDavid E. O'Brien 	 strtoull __P((const char *, char **, int));
12059deaec5SRodney W. Grimes int	 system __P((const char *));
12159deaec5SRodney W. Grimes 
12259deaec5SRodney W. Grimes int	 mblen __P((const char *, size_t));
12359deaec5SRodney W. Grimes size_t	 mbstowcs __P((wchar_t *, const char *, size_t));
12459deaec5SRodney W. Grimes int	 wctomb __P((char *, wchar_t));
12559deaec5SRodney W. Grimes int	 mbtowc __P((wchar_t *, const char *, size_t));
12659deaec5SRodney W. Grimes size_t	 wcstombs __P((char *, const wchar_t *, size_t));
12759deaec5SRodney W. Grimes 
1287a4a6327SMike Barcroft #ifdef __LONG_LONG_SUPPORTED
1297a4a6327SMike Barcroft long long
1307a4a6327SMike Barcroft 	 llabs __P((long long)) __pure2;
1317a4a6327SMike Barcroft lldiv_t	 lldiv __P((long long, long long)) __pure2;
1327a4a6327SMike Barcroft #endif
1337a4a6327SMike Barcroft 
13467c54240SBruce Evans #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
135798c1fd8SPoul-Henning Kamp extern char *_malloc_options;
136798c1fd8SPoul-Henning Kamp extern void (*_malloc_message)__P((char *p1, char *p2, char *p3, char *p4));
137798c1fd8SPoul-Henning Kamp 
13859deaec5SRodney W. Grimes int	 putenv __P((const char *));
13959deaec5SRodney W. Grimes int	 setenv __P((const char *, const char *, int));
14059deaec5SRodney W. Grimes 
141f8f6d0dcSAndreas Schulz double	 drand48 __P((void));
142f8f6d0dcSAndreas Schulz double	 erand48 __P((unsigned short[3]));
143f8f6d0dcSAndreas Schulz long	 jrand48 __P((unsigned short[3]));
144f8f6d0dcSAndreas Schulz void	 lcong48 __P((unsigned short[7]));
14567c54240SBruce Evans long	 lrand48 __P((void));
14667c54240SBruce Evans long	 mrand48 __P((void));
14767c54240SBruce Evans long	 nrand48 __P((unsigned short[3]));
14867c54240SBruce Evans unsigned short
14967c54240SBruce Evans 	*seed48 __P((unsigned short[3]));
15067c54240SBruce Evans void	 srand48 __P((long));
151f8f6d0dcSAndreas Schulz 
15259deaec5SRodney W. Grimes void	*alloca __P((size_t));		/* built-in for gcc */
15359deaec5SRodney W. Grimes 					/* getcap(3) functions */
1548252a465SDmitrij Tejblum __uint32_t
155b24d5f1dSAndrey A. Chernov 	 arc4random __P((void));
156b24d5f1dSAndrey A. Chernov void	 arc4random_addrandom __P((unsigned char *dat, int datlen));
157439c8bdaSAndrey A. Chernov void	 arc4random_stir __P((void));
15859deaec5SRodney W. Grimes char	*getbsize __P((int *, long *));
15959deaec5SRodney W. Grimes char	*cgetcap __P((char *, char *, int));
16059deaec5SRodney W. Grimes int	 cgetclose __P((void));
16159deaec5SRodney W. Grimes int	 cgetent __P((char **, char **, char *));
16259deaec5SRodney W. Grimes int	 cgetfirst __P((char **, char **));
16359deaec5SRodney W. Grimes int	 cgetmatch __P((char *, char *));
16459deaec5SRodney W. Grimes int	 cgetnext __P((char **, char **));
16559deaec5SRodney W. Grimes int	 cgetnum __P((char *, char *, long *));
16659deaec5SRodney W. Grimes int	 cgetset __P((char *));
16759deaec5SRodney W. Grimes int	 cgetstr __P((char *, char *, char **));
16859deaec5SRodney W. Grimes int	 cgetustr __P((char *, char *, char **));
16959deaec5SRodney W. Grimes 
17059deaec5SRodney W. Grimes int	 daemon __P((int, int));
17159deaec5SRodney W. Grimes char	*devname __P((int, int));
17259deaec5SRodney W. Grimes int	 getloadavg __P((double [], int));
173cd18ccdcSDima Dorfman const char *
174cd18ccdcSDima Dorfman 	getprogname __P((void));
17559deaec5SRodney W. Grimes 
17659deaec5SRodney W. Grimes char	*group_from_gid __P((unsigned long, int));
17759deaec5SRodney W. Grimes int	 heapsort __P((void *, size_t, size_t,
17859deaec5SRodney W. Grimes 	    int (*)(const void *, const void *)));
179c59376afSPeter Wemm char	*initstate __P((unsigned long, char *, long));
18059deaec5SRodney W. Grimes int	 mergesort __P((void *, size_t, size_t,
18159deaec5SRodney W. Grimes 	    int (*)(const void *, const void *)));
18259deaec5SRodney W. Grimes int	 radixsort __P((const unsigned char **, int, const unsigned char *,
18359deaec5SRodney W. Grimes 	    unsigned));
18459deaec5SRodney W. Grimes int	 sradixsort __P((const unsigned char **, int, const unsigned char *,
18559deaec5SRodney W. Grimes 	    unsigned));
186dea750aeSBruce Evans int	 rand_r __P((unsigned *));
18759deaec5SRodney W. Grimes long	 random __P((void));
18894ad719cSWarner Losh void    *reallocf __P((void *, size_t));
18959deaec5SRodney W. Grimes char	*realpath __P((const char *, char resolved_path[]));
190cd18ccdcSDima Dorfman void	 setprogname __P((const char *));
19159deaec5SRodney W. Grimes char	*setstate __P((char *));
192c59376afSPeter Wemm void	 srandom __P((unsigned long));
19399596f82SAndrey A. Chernov void	 sranddev __P((void));
19496c31b26SAndrey A. Chernov void	 srandomdev __P((void));
19559deaec5SRodney W. Grimes char	*user_from_uid __P((unsigned long, int));
19659deaec5SRodney W. Grimes #ifndef __STRICT_ANSI__
1978252a465SDmitrij Tejblum __int64_t	 strtoq __P((const char *, char **, int));
1988252a465SDmitrij Tejblum __uint64_t
19959deaec5SRodney W. Grimes 	 strtouq __P((const char *, char **, int));
20059deaec5SRodney W. Grimes #endif
20159deaec5SRodney W. Grimes void	 unsetenv __P((const char *));
20267c54240SBruce Evans #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
20359deaec5SRodney W. Grimes __END_DECLS
20459deaec5SRodney W. Grimes 
20567c54240SBruce Evans #endif /* !_STDLIB_H_ */
206