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