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