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