stdlib.h revision 99640
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1990, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
3323657Speter *	@(#)stdlib.h	8.5 (Berkeley) 5/19/95
3455031Sbde * $FreeBSD: head/include/stdlib.h 99640 2002-07-09 05:13:30Z obrien $
351539Srgrimes */
361539Srgrimes
371539Srgrimes#ifndef _STDLIB_H_
387865Sbde#define	_STDLIB_H_
391539Srgrimes
4033861Sbde#include <sys/cdefs.h>
4133861Sbde
421539Srgrimes#include <machine/ansi.h>
4326636Sache
4426636Sache#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
4515483Sbde#ifdef	_BSD_RUNE_T_
4615483Sbdetypedef	_BSD_RUNE_T_	rune_t;
4715483Sbde#undef	_BSD_RUNE_T_
4815483Sbde#endif
4915483Sbde#endif
5015483Sbde
511539Srgrimes#ifdef	_BSD_SIZE_T_
521539Srgrimestypedef	_BSD_SIZE_T_	size_t;
531539Srgrimes#undef	_BSD_SIZE_T_
541539Srgrimes#endif
551539Srgrimes
5699640Sobrien#ifndef	__cplusplus
571539Srgrimes#ifdef	_BSD_WCHAR_T_
581539Srgrimestypedef	_BSD_WCHAR_T_	wchar_t;
591539Srgrimes#undef	_BSD_WCHAR_T_
601539Srgrimes#endif
6199640Sobrien#endif
621539Srgrimes
631539Srgrimestypedef struct {
641539Srgrimes	int quot;		/* quotient */
651539Srgrimes	int rem;		/* remainder */
661539Srgrimes} div_t;
671539Srgrimes
681539Srgrimestypedef struct {
691539Srgrimes	long quot;		/* quotient */
701539Srgrimes	long rem;		/* remainder */
711539Srgrimes} ldiv_t;
721539Srgrimes
7387071Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
7486368Smike#ifdef __LONG_LONG_SUPPORTED
7599404Smarkm/* LONGLONG */
7686368Smiketypedef struct {
7786368Smike	long long quot;
7886368Smike	long long rem;
7986368Smike} lldiv_t;
8086368Smike#endif
8187071Sbde#endif
8286368Smike
831539Srgrimes#ifndef NULL
841539Srgrimes#define	NULL	0
851539Srgrimes#endif
861539Srgrimes
871539Srgrimes#define	EXIT_FAILURE	1
881539Srgrimes#define	EXIT_SUCCESS	0
891539Srgrimes
901539Srgrimes#define	RAND_MAX	0x7fffffff
911539Srgrimes
921539Srgrimesextern int __mb_cur_max;
931539Srgrimes#define	MB_CUR_MAX	__mb_cur_max
941539Srgrimes
951539Srgrimes__BEGIN_DECLS
9693032Simpvoid	 abort(void) __dead2;
9793032Simpint	 abs(int) __pure2;
9893032Simpint	 atexit(void (*)(void));
9993032Simpdouble	 atof(const char *);
10093032Simpint	 atoi(const char *);
10193032Simplong	 atol(const char *);
10293032Simpvoid	*bsearch(const void *, const void *, size_t,
10393032Simp	    size_t, int (*)(const void *, const void *));
10493032Simpvoid	*calloc(size_t, size_t);
10593032Simpdiv_t	 div(int, int) __pure2;
10693032Simpvoid	 exit(int) __dead2;
10793032Simpvoid	 free(void *);
10893032Simpchar	*getenv(const char *);
10993032Simplong	 labs(long) __pure2;
11093032Simpldiv_t	 ldiv(long, long) __pure2;
11193032Simpvoid	*malloc(size_t);
11293032Simpvoid	 qsort(void *, size_t, size_t,
11393032Simp	    int (*)(const void *, const void *));
11493032Simpint	 rand(void);
11593032Simpvoid	*realloc(void *, size_t);
11693032Simpvoid	 srand(unsigned);
11793032Simpdouble	 strtod(const char *, char **);
11893032Simplong	 strtol(const char *, char **, int);
1191539Srgrimesunsigned long
12093032Simp	 strtoul(const char *, char **, int);
12193032Simpint	 system(const char *);
1221539Srgrimes
12393032Simpint	 mblen(const char *, size_t);
12493032Simpsize_t	 mbstowcs(wchar_t *, const char *, size_t);
12593032Simpint	 wctomb(char *, wchar_t);
12693032Simpint	 mbtowc(wchar_t *, const char *, size_t);
12793032Simpsize_t	 wcstombs(char *, const wchar_t *, size_t);
1281539Srgrimes
1297865Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
13095377Sphkextern const char *_malloc_options;
13197639Sphkextern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4);
13269201Sphk
13393032Simpint	 putenv(const char *);
13493032Simpint	 setenv(const char *, const char *, int);
1351539Srgrimes
13693032Simpdouble	 drand48(void);
13793032Simpdouble	 erand48(unsigned short[3]);
13893032Simplong	 jrand48(unsigned short[3]);
13993032Simpvoid	 lcong48(unsigned short[7]);
14093032Simplong	 lrand48(void);
14193032Simplong	 mrand48(void);
14293032Simplong	 nrand48(unsigned short[3]);
1437865Sbdeunsigned short
14493032Simp	*seed48(unsigned short[3]);
14593032Simpvoid	 srand48(long);
1464749Sats
14793032Simpvoid	*alloca(size_t);		/* built-in for gcc */
1481539Srgrimes					/* getcap(3) functions */
14941927Sdt__uint32_t
15093032Simp	 arc4random(void);
15193032Simpvoid	 arc4random_addrandom(unsigned char *dat, int datlen);
15293032Simpvoid	 arc4random_stir(void);
15387086Sbde#ifdef __LONG_LONG_SUPPORTED
15499404Smarkm/* LONGLONG */
15587086Sbdelong long
15693032Simp	 atoll(const char *);
15787086Sbde#endif
15893032Simpchar	*getbsize(int *, long *);
15993032Simpchar	*cgetcap(char *, const char *, int);
16093032Simpint	 cgetclose(void);
16193032Simpint	 cgetent(char **, char **, const char *);
16293032Simpint	 cgetfirst(char **, char **);
16393032Simpint	 cgetmatch(const char *, const char *);
16493032Simpint	 cgetnext(char **, char **);
16593032Simpint	 cgetnum(char *, const char *, long *);
16693032Simpint	 cgetset(const char *);
16793032Simpint	 cgetstr(char *, const char *, char **);
16893032Simpint	 cgetustr(char *, const char *, char **);
1691539Srgrimes
17093032Simpint	 daemon(int, int);
17193032Simpchar	*devname(int, int);
17293032Simpint	 getloadavg(double [], int);
17388399Smike__const char *
17493032Simp	 getprogname(void);
1751539Srgrimes
17693032Simpint	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
17793032Simpchar	*initstate(unsigned long, char *, long);
17887071Sbde#ifdef __LONG_LONG_SUPPORTED
17999404Smarkm/* LONGLONG */
18087071Sbdelong long
18193032Simp	 llabs(long long) __pure2;
18293032Simplldiv_t	 lldiv(long long, long long) __pure2;
18387071Sbde#endif
18493032Simpint	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
18593032Simpint	 radixsort(const unsigned char **, int, const unsigned char *,
18693032Simp	    unsigned);
18793032Simpint	 sradixsort(const unsigned char **, int, const unsigned char *,
18893032Simp	    unsigned);
18993032Simpint	 rand_r(unsigned *);
19093032Simplong	 random(void);
19193032Simpvoid    *reallocf(void *, size_t);
19293032Simpchar	*realpath(const char *, char resolved_path[]);
19393032Simpvoid	 setprogname(const char *);
19493032Simpchar	*setstate(char *);
19593032Simpvoid	 sranddev(void);
19693032Simpvoid	 srandom(unsigned long);
19793032Simpvoid	 srandomdev(void);
19887071Sbde#ifdef __LONG_LONG_SUPPORTED
19999404Smarkm/* LONGLONG */
20087071Sbdelong long
20193032Simp	 strtoll(const char *, char **, int);
20287071Sbde#endif
20393032Simp__int64_t	 strtoq(const char *, char **, int);
20487071Sbde#ifdef __LONG_LONG_SUPPORTED
20599404Smarkm/* LONGLONG */
20687071Sbdeunsigned long long
20793032Simp	 strtoull(const char *, char **, int);
20887071Sbde#endif
20941927Sdt__uint64_t
21093032Simp	 strtouq(const char *, char **, int);
21193032Simpvoid	 unsetenv(const char *);
2127865Sbde#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
2131539Srgrimes__END_DECLS
2141539Srgrimes
2157865Sbde#endif /* !_STDLIB_H_ */
216