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.
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.
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]
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 2013 Gary Mills
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
31 /* Copyright (c) 1988 AT&T */
32 /* All Rights Reserved */
37 #include <iso/stdlib_iso.h>
38 #include <iso/stdlib_c99.h>
39 #include <iso/stdlib_c11.h>
41 #if defined(__EXTENSIONS__) || defined(_XPG4)
46 * Allow global visibility for symbols defined in
47 * C++ "std" namespace in <iso/stdlib_iso.h>.
49 #if __cplusplus >= 199711L
89 typedef unsigned int uid_t
; /* UID type */
92 /* large file compilation environment setup */
93 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
95 #ifdef __PRAGMA_REDEFINE_EXTNAME
96 #pragma redefine_extname mkstemp mkstemp64
97 #pragma redefine_extname mkstemps mkstemps64
98 #pragma redefine_extname mkostemp mkostemp64
99 #pragma redefine_extname mkostemps mkostemps64
100 #else /* __PRAGMA_REDEFINE_EXTNAME */
101 #define mkstemp mkstemp64
102 #define mkstemps mkstemps64
103 #define mkostemp mkostemp64
104 #define mkostemps mkostemps64
105 #endif /* __PRAGMA_REDEFINE_EXTNAME */
107 #endif /* _FILE_OFFSET_BITS == 64 */
109 /* In the LP64 compilation environment, all APIs are already large file */
110 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
112 #ifdef __PRAGMA_REDEFINE_EXTNAME
113 #pragma redefine_extname mkstemp64 mkstemp
114 #pragma redefine_extname mkstemps64 mkstemps
115 #pragma redefine_extname mkostemp64 mkostemp
116 #pragma redefine_extname mkostemps64 mkostemps
117 #else /* __PRAGMA_REDEFINE_EXTNAME */
118 #define mkstemp64 mkstemp
119 #define mkstemps64 mkstemps
120 #define mkostemp64 mkostemp
121 #define mkostemps64 mkostemps
122 #endif /* __PRAGMA_REDEFINE_EXTNAME */
124 #endif /* _LP64 && _LARGEFILE64_SOURCE */
126 #if defined(__EXTENSIONS__) || \
127 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
128 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
129 extern int rand_r(unsigned int *);
132 extern void _exithandle(void);
134 #if defined(__EXTENSIONS__) || \
135 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
137 extern double drand48(void);
138 extern double erand48(unsigned short *);
139 extern long jrand48(unsigned short *);
140 extern void lcong48(unsigned short *);
141 extern long lrand48(void);
142 extern long mrand48(void);
143 extern long nrand48(unsigned short *);
144 extern unsigned short *seed48(unsigned short *);
145 extern void srand48(long);
146 extern int putenv(char *);
147 extern void setkey(const char *);
148 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
151 * swab() has historically been in <stdlib.h> as delivered from AT&T
152 * and continues to be visible in the default compilation environment.
153 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
154 * in <unistd.h>. As a result, with respect to X/Open namespace the
155 * swab() declaration in this header is only visible for the XPG3
158 #if (defined(__EXTENSIONS__) || \
159 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
160 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
163 #if defined(_LP64) || defined(_I32LPx)
164 typedef long ssize_t
; /* size of something in bytes or -1 */
166 typedef int ssize_t
; /* (historical version) */
168 #endif /* !_SSIZE_T */
170 extern void swab(const char *, char *, ssize_t
);
171 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
173 #if defined(__EXTENSIONS__) || \
174 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
175 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
176 extern int mkstemp(char *);
177 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
178 extern int mkstemps(char *, int);
180 #endif /* defined(__EXTENSIONS__) ... */
182 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
183 !defined(__PRAGMA_REDEFINE_EXTNAME))
184 extern int mkstemp64(char *);
185 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
186 extern int mkstemps64(char *, int);
188 #endif /* _LARGEFILE64_SOURCE... */
190 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
191 extern char *mkdtemp(char *);
192 #endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
194 #if !defined(_STRICT_SYMBOLS)
195 extern int mkostemp(char *, int);
196 extern int mkostemps(char *, int, int);
197 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
198 !defined(__PRAGMA_REDEFINE_EXTNAME))
199 extern int mkostemp64(char *, int);
200 extern int mkostemps64(char *, int, int);
201 #endif /* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */
202 #endif /* !defined(_STRICT_SYMBOLS) */
204 #if defined(__EXTENSIONS__) || \
205 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
207 extern long a64l(const char *);
208 extern char *ecvt(double, int, int *_RESTRICT_KYWD
, int *_RESTRICT_KYWD
);
209 extern char *fcvt(double, int, int *_RESTRICT_KYWD
, int *_RESTRICT_KYWD
);
210 extern char *gcvt(double, int, char *);
211 extern int getsubopt(char **, char *const *, char **);
212 extern int grantpt(int);
213 extern char *initstate(unsigned, char *, size_t);
214 extern char *l64a(long);
215 extern char *mktemp(char *);
216 extern char *ptsname(int);
217 extern long random(void);
218 extern char *realpath(const char *_RESTRICT_KYWD
, char *_RESTRICT_KYWD
);
219 extern char *setstate(const char *);
220 extern void srandom(unsigned);
221 extern int unlockpt(int);
222 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
223 #if !defined(_XPG6) || defined(__EXTENSIONS__)
224 extern int ttyslot(void);
225 extern void *valloc(size_t);
226 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
227 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
229 #if defined(__EXTENSIONS__) || \
230 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
232 extern int posix_memalign(void **, size_t, size_t);
233 extern int posix_openpt(int);
234 extern int setenv(const char *, const char *, int);
235 extern int unsetenv(const char *);
238 #if defined(__EXTENSIONS__) || \
239 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
240 extern char *canonicalize_file_name(const char *);
241 extern int clearenv(void);
242 extern void closefrom(int);
243 extern int daemon(int, int);
244 extern int dup2(int, int);
245 extern int dup3(int, int, int);
246 extern int fdwalk(int (*)(void *, int), void *);
247 extern char *qecvt(long double, int, int *, int *);
248 extern char *qfcvt(long double, int, int *, int *);
249 extern char *qgcvt(long double, int, char *);
250 extern char *getcwd(char *, size_t);
251 extern const char *getexecname(void);
253 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */
254 #define __GETLOGIN_DEFINED
255 #ifndef __USE_LEGACY_LOGNAME__
256 #ifdef __PRAGMA_REDEFINE_EXTNAME
257 #pragma redefine_extname getlogin getloginx
258 #else /* __PRAGMA_REDEFINE_EXTNAME */
259 extern char *getloginx(void);
260 #define getlogin getloginx
261 #endif /* __PRAGMA_REDEFINE_EXTNAME */
262 #endif /* __USE_LEGACY_LOGNAME__ */
263 extern char *getlogin(void);
264 #endif /* __GETLOGIN_DEFINED */
266 extern int getopt(int, char *const *, const char *);
268 extern int optind
, opterr
, optopt
;
269 extern char *getpass(const char *);
270 extern char *getpassphrase(const char *);
271 extern int getpw(uid_t
, char *);
272 extern int isatty(int);
273 extern void *memalign(size_t, size_t);
274 extern char *ttyname(int);
275 extern char *mkdtemp(char *);
276 extern const char *getprogname(void);
277 extern void setprogname(const char *);
279 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
280 extern char *lltostr(long long, char *);
281 extern char *ulltostr(unsigned long long, char *);
282 #endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
284 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
286 /* OpenBSD compatibility functions */
287 #if !defined(_STRICT_SYMBOLS)
289 #include <inttypes.h>
290 extern uint32_t arc4random(void);
291 extern void arc4random_buf(void *, size_t);
292 extern uint32_t arc4random_uniform(uint32_t);
294 #endif /* !_STRICT_SYBMOLS */
301 #endif /* _STDLIB_H */