xref: /illumos-gate/usr/src/head/stdlib.h (revision d8109ce4330e1b8ad6c29f9fccacec969066bb9d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24  * Copyright (c) 2013 Gary Mills
25  *
26  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27  */
28 
29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30 
31 /*	Copyright (c) 1988 AT&T	*/
32 /*	  All Rights Reserved	*/
33 
34 #ifndef _STDLIB_H
35 #define	_STDLIB_H
36 
37 #include <iso/stdlib_iso.h>
38 #include <iso/stdlib_c99.h>
39 #include <iso/stdlib_c11.h>
40 
41 #if defined(__EXTENSIONS__) || defined(_XPG4)
42 #include <sys/wait.h>
43 #endif
44 
45 /*
46  * Allow global visibility for symbols defined in
47  * C++ "std" namespace in <iso/stdlib_iso.h>.
48  */
49 #if __cplusplus >= 199711L
50 using std::div_t;
51 using std::ldiv_t;
52 using std::size_t;
53 using std::abort;
54 using std::abs;
55 using std::atexit;
56 using std::atof;
57 using std::atoi;
58 using std::atol;
59 using std::bsearch;
60 using std::calloc;
61 using std::div;
62 using std::exit;
63 using std::free;
64 using std::getenv;
65 using std::labs;
66 using std::ldiv;
67 using std::malloc;
68 using std::mblen;
69 using std::mbstowcs;
70 using std::mbtowc;
71 using std::qsort;
72 using std::rand;
73 using std::realloc;
74 using std::srand;
75 using std::strtod;
76 using std::strtol;
77 using std::strtoul;
78 using std::system;
79 using std::wcstombs;
80 using std::wctomb;
81 #endif
82 
83 /*
84  * Allow global visibility for symbols defined in
85  * C++ "std" namespace in <iso/stdlib_c11.h>.
86  */
87 #if __cplusplus >= 201103L
88 using std::at_quick_exit;
89 using std::quick_exit;
90 #endif
91 #if __cplusplus >= 201703L
92 using std::aligned_alloc;
93 #endif
94 
95 #ifdef	__cplusplus
96 extern "C" {
97 #endif
98 
99 #ifndef _UID_T
100 #define	_UID_T
101 typedef	unsigned int	uid_t;		/* UID type		*/
102 #endif	/* !_UID_T */
103 
104 /* large file compilation environment setup */
105 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
106 
107 #ifdef	__PRAGMA_REDEFINE_EXTNAME
108 #pragma redefine_extname	mkstemp		mkstemp64
109 #pragma redefine_extname	mkstemps	mkstemps64
110 #pragma	redefine_extname	mkostemp	mkostemp64
111 #pragma	redefine_extname	mkostemps	mkostemps64
112 #else	/* __PRAGMA_REDEFINE_EXTNAME */
113 #define	mkstemp			mkstemp64
114 #define	mkstemps		mkstemps64
115 #define	mkostemp		mkostemp64
116 #define	mkostemps		mkostemps64
117 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
118 
119 #endif	/* _FILE_OFFSET_BITS == 64 */
120 
121 /* In the LP64 compilation environment, all APIs are already large file */
122 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
123 
124 #ifdef	__PRAGMA_REDEFINE_EXTNAME
125 #pragma redefine_extname	mkstemp64	mkstemp
126 #pragma redefine_extname	mkstemps64	mkstemps
127 #pragma	redefine_extname	mkostemp64	mkostemp
128 #pragma	redefine_extname	mkostemps64	mkostemps
129 #else	/* __PRAGMA_REDEFINE_EXTNAME */
130 #define	mkstemp64		mkstemp
131 #define	mkstemps64		mkstemps
132 #define	mkostemp64		mkostemp
133 #define	mkostemps64		mkostemps
134 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
135 
136 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
137 
138 #if defined(__EXTENSIONS__) || \
139 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
140 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
141 extern int rand_r(unsigned int *);
142 #endif
143 
144 extern void _exithandle(void);
145 
146 #if defined(__EXTENSIONS__) || \
147 	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
148 	defined(_XPG4)
149 extern double drand48(void);
150 extern double erand48(unsigned short *);
151 extern long jrand48(unsigned short *);
152 extern void lcong48(unsigned short *);
153 extern long lrand48(void);
154 extern long mrand48(void);
155 extern long nrand48(unsigned short *);
156 extern unsigned short *seed48(unsigned short *);
157 extern void srand48(long);
158 extern int putenv(char *);
159 extern void setkey(const char *);
160 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
161 
162 /*
163  * swab() has historically been in <stdlib.h> as delivered from AT&T
164  * and continues to be visible in the default compilation environment.
165  * As of Issue 4 of the X/Open Portability Guides, swab() was declared
166  * in <unistd.h>. As a result, with respect to X/Open namespace the
167  * swab() declaration in this header is only visible for the XPG3
168  * environment.
169  */
170 #if (defined(__EXTENSIONS__) || \
171 	(!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
172 	(!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
173 #ifndef	_SSIZE_T
174 #define	_SSIZE_T
175 #if defined(_LP64) || defined(_I32LPx)
176 typedef long	ssize_t;	/* size of something in bytes or -1 */
177 #else
178 typedef int	ssize_t;	/* (historical version) */
179 #endif
180 #endif	/* !_SSIZE_T */
181 
182 extern void swab(const char *, char *, ssize_t);
183 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
184 
185 #if defined(__EXTENSIONS__) || \
186 	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
187 	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
188 extern int	mkstemp(char *);
189 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
190 extern int	mkstemps(char *, int);
191 #endif
192 #endif /* defined(__EXTENSIONS__) ... */
193 
194 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
195 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
196 extern int	mkstemp64(char *);
197 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
198 extern int	mkstemps64(char *, int);
199 #endif
200 #endif	/* _LARGEFILE64_SOURCE... */
201 
202 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
203 extern char	*mkdtemp(char *);
204 #endif	/* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
205 
206 #if !defined(_STRICT_SYMBOLS)
207 extern int		mkostemp(char *, int);
208 extern int		mkostemps(char *, int, int);
209 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
210 		!defined(__PRAGMA_REDEFINE_EXTNAME))
211 extern int		mkostemp64(char *, int);
212 extern int		mkostemps64(char *, int, int);
213 #endif	/* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */
214 #endif	/* !defined(_STRICT_SYMBOLS) */
215 
216 #if defined(__EXTENSIONS__) || \
217 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
218 	defined(_XPG4_2)
219 extern long a64l(const char *);
220 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
221 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
222 extern char *gcvt(double, int, char *);
223 extern int getsubopt(char **, char *const *, char **);
224 extern int  grantpt(int);
225 extern char *initstate(unsigned, char *, size_t);
226 extern char *l64a(long);
227 extern char *mktemp(char *);
228 extern char *ptsname(int);
229 extern long random(void);
230 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
231 extern char *setstate(const char *);
232 extern void srandom(unsigned);
233 extern int  unlockpt(int);
234 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
235 #if !defined(_XPG6) || defined(__EXTENSIONS__)
236 extern int ttyslot(void);
237 extern void *valloc(size_t);
238 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
239 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
240 
241 #if defined(__EXTENSIONS__) || \
242 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
243 	defined(_XPG6)
244 extern int posix_memalign(void **, size_t, size_t);
245 extern int posix_openpt(int);
246 extern int setenv(const char *, const char *, int);
247 extern int unsetenv(const char *);
248 #endif
249 
250 #if defined(__EXTENSIONS__) || \
251 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
252 extern char *canonicalize_file_name(const char *);
253 extern int clearenv(void);
254 extern void closefrom(int);
255 extern int daemon(int, int);
256 extern int dup2(int, int);
257 extern int dup3(int, int, int);
258 extern int fdwalk(int (*)(void *, int), void *);
259 extern char *qecvt(long double, int, int *, int *);
260 extern char *qfcvt(long double, int, int *, int *);
261 extern char *qgcvt(long double, int, char *);
262 extern char *getcwd(char *, size_t);
263 extern const char *getexecname(void);
264 
265 #ifndef	__GETLOGIN_DEFINED	/* Avoid duplicate in unistd.h */
266 #define	__GETLOGIN_DEFINED
267 #ifndef	__USE_LEGACY_LOGNAME__
268 #ifdef	__PRAGMA_REDEFINE_EXTNAME
269 #pragma	redefine_extname getlogin getloginx
270 #else	/* __PRAGMA_REDEFINE_EXTNAME */
271 extern char *getloginx(void);
272 #define	getlogin	getloginx
273 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
274 #endif	/* __USE_LEGACY_LOGNAME__ */
275 extern char *getlogin(void);
276 #endif	/* __GETLOGIN_DEFINED */
277 
278 extern int getopt(int, char *const *, const char *);
279 extern char *optarg;
280 extern int optind, opterr, optopt;
281 extern char *getpass(const char *);
282 extern char *getpassphrase(const char *);
283 extern int getpw(uid_t, char *);
284 extern int isatty(int);
285 extern void *memalign(size_t, size_t);
286 extern char *ttyname(int);
287 extern char *mkdtemp(char *);
288 extern const char *getprogname(void);
289 extern void setprogname(const char *);
290 
291 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
292 extern char *lltostr(long long, char *);
293 extern char *ulltostr(unsigned long long, char *);
294 #endif	/* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
295 
296 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
297 
298 /* OpenBSD compatibility functions */
299 #if !defined(_STRICT_SYMBOLS)
300 
301 #include <inttypes.h>
302 extern uint32_t arc4random(void);
303 extern void arc4random_buf(void *, size_t);
304 extern uint32_t arc4random_uniform(uint32_t);
305 extern void freezero(void *, size_t);
306 extern void *reallocarray(void *, size_t, size_t);
307 extern void *recallocarray(void *, size_t, size_t, size_t);
308 extern long long strtonum(const char *, long long, long long, const char **);
309 
310 #endif	/* !_STRICT_SYBMOLS */
311 
312 
313 #ifdef	__cplusplus
314 }
315 #endif
316 
317 #endif	/* _STDLIB_H */
318