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