xref: /titanic_52/usr/src/head/stdlib.h (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
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 typedef	unsigned int	uid_t;		/* UID type		*/
87 #endif	/* !_UID_T */
88 
89 #if defined(__STDC__)
90 
91 /* large file compilation environment setup */
92 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
93 
94 #ifdef	__PRAGMA_REDEFINE_EXTNAME
95 #pragma redefine_extname	mkstemp		mkstemp64
96 #pragma redefine_extname	mkstemps	mkstemps64
97 #else	/* __PRAGMA_REDEFINE_EXTNAME */
98 #define	mkstemp			mkstemp64
99 #define	mkstemps		mkstemps64
100 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
101 
102 #endif	/* _FILE_OFFSET_BITS == 64 */
103 
104 /* In the LP64 compilation environment, all APIs are already large file */
105 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
106 
107 #ifdef	__PRAGMA_REDEFINE_EXTNAME
108 #pragma redefine_extname	mkstemp64	mkstemp
109 #pragma redefine_extname	mkstemps64	mkstemps
110 #else	/* __PRAGMA_REDEFINE_EXTNAME */
111 #define	mkstemp64		mkstemp
112 #define	mkstemps64		mkstemps
113 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
114 
115 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
116 
117 #if defined(__EXTENSIONS__) || \
118 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
119 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
120 extern int rand_r(unsigned int *);
121 #endif
122 
123 extern void _exithandle(void);
124 
125 #if defined(__EXTENSIONS__) || \
126 	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
127 	defined(_XPG4)
128 extern double drand48(void);
129 extern double erand48(unsigned short *);
130 extern long jrand48(unsigned short *);
131 extern void lcong48(unsigned short *);
132 extern long lrand48(void);
133 extern long mrand48(void);
134 extern long nrand48(unsigned short *);
135 extern unsigned short *seed48(unsigned short *);
136 extern void srand48(long);
137 extern int putenv(char *);
138 extern void setkey(const char *);
139 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
140 
141 /*
142  * swab() has historically been in <stdlib.h> as delivered from AT&T
143  * and continues to be visible in the default compilation environment.
144  * As of Issue 4 of the X/Open Portability Guides, swab() was declared
145  * in <unistd.h>. As a result, with respect to X/Open namespace the
146  * swab() declaration in this header is only visible for the XPG3
147  * environment.
148  */
149 #if (defined(__EXTENSIONS__) || \
150 	(!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
151 	(!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
152 #ifndef	_SSIZE_T
153 #define	_SSIZE_T
154 #if defined(_LP64) || defined(_I32LPx)
155 typedef long	ssize_t;	/* size of something in bytes or -1 */
156 #else
157 typedef int	ssize_t;	/* (historical version) */
158 #endif
159 #endif	/* !_SSIZE_T */
160 
161 extern void swab(const char *, char *, ssize_t);
162 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
163 
164 #if defined(__EXTENSIONS__) || \
165 	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
166 	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
167 extern int	mkstemp(char *);
168 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
169 extern int	mkstemps(char *, int);
170 #endif
171 #endif /* defined(__EXTENSIONS__) ... */
172 
173 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
174 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
175 extern int	mkstemp64(char *);
176 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
177 extern int	mkstemps64(char *, int);
178 #endif
179 #endif	/* _LARGEFILE64_SOURCE... */
180 
181 #if defined(__EXTENSIONS__) || \
182 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
183 	defined(_XPG4_2)
184 extern long a64l(const char *);
185 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
186 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
187 extern char *gcvt(double, int, char *);
188 extern int getsubopt(char **, char *const *, char **);
189 extern int  grantpt(int);
190 extern char *initstate(unsigned, char *, size_t);
191 extern char *l64a(long);
192 extern char *mktemp(char *);
193 extern char *ptsname(int);
194 extern long random(void);
195 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
196 extern char *setstate(const char *);
197 extern void srandom(unsigned);
198 extern int  unlockpt(int);
199 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
200 #if !defined(_XPG6) || defined(__EXTENSIONS__)
201 extern int ttyslot(void);
202 extern void *valloc(size_t);
203 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
204 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
205 
206 #if defined(__EXTENSIONS__) || \
207 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
208 	defined(_XPG6)
209 extern int posix_memalign(void **, size_t, size_t);
210 extern int posix_openpt(int);
211 extern int setenv(const char *, const char *, int);
212 extern int unsetenv(const char *);
213 #endif
214 
215 #if defined(__EXTENSIONS__) || \
216 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
217 extern void closefrom(int);
218 extern int dup2(int, int);
219 extern int fdwalk(int (*)(void *, int), void *);
220 extern char *qecvt(long double, int, int *, int *);
221 extern char *qfcvt(long double, int, int *, int *);
222 extern char *qgcvt(long double, int, char *);
223 extern char *getcwd(char *, size_t);
224 extern const char *getexecname(void);
225 extern char *getlogin(void);
226 extern int getopt(int, char *const *, const char *);
227 extern char *optarg;
228 extern int optind, opterr, optopt;
229 extern char *getpass(const char *);
230 extern char *getpassphrase(const char *);
231 extern int getpw(uid_t, char *);
232 extern int isatty(int);
233 extern void *memalign(size_t, size_t);
234 extern char *ttyname(int);
235 extern char *mkdtemp(char *);
236 
237 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
238 extern char *lltostr(long long, char *);
239 extern char *ulltostr(unsigned long long, char *);
240 #endif	/* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
241 
242 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
243 
244 #else /* not __STDC__ */
245 
246 #if defined(__EXTENSIONS__) || !defined(_XOPEN_OR_POSIX) || \
247 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
248 extern int rand_r();
249 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT) ... */
250 
251 extern void _exithandle();
252 
253 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || defined(_XPG4)
254 extern double drand48();
255 extern double erand48();
256 extern long jrand48();
257 extern void lcong48();
258 extern long lrand48();
259 extern long mrand48();
260 extern long nrand48();
261 extern unsigned short *seed48();
262 extern void srand48();
263 extern int putenv();
264 extern void setkey();
265 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
266 
267 #if (defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)) && \
268 	(!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
269 extern void swab();
270 #endif
271 
272 #if defined(__EXTENSIONS__) || \
273 	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
274 	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
275 extern int	mkstemp();
276 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
277 extern int	mkstemps();
278 #endif
279 #endif	/* defined(__EXTENSIONS__) ... */
280 
281 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
282 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
283 extern int	mkstemp64();
284 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
285 extern int	mkstemps64();
286 #endif
287 #endif	/* _LARGEFILE64_SOURCE... */
288 
289 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
290 extern long a64l();
291 extern char *ecvt();
292 extern char *fcvt();
293 extern char *gcvt();
294 extern int getsubopt();
295 extern int grantpt();
296 extern char *initstate();
297 extern char *l64a();
298 extern char *mktemp();
299 extern char *ptsname();
300 extern long random();
301 extern char *realpath();
302 extern char *setstate();
303 extern void srandom();
304 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
305 #if !defined(_XPG6) || defined(__EXTENSIONS__)
306 extern int ttyslot();
307 extern void *valloc();
308 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
309 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
310 
311 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6)
312 extern int posix_memalign();
313 extern int posix_openpt();
314 extern int setenv();
315 extern int unsetenv();
316 #endif
317 
318 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
319 extern void closefrom();
320 extern int dup2();
321 extern int fdwalk();
322 extern char *qecvt();
323 extern char *qfcvt();
324 extern char *qgcvt();
325 extern char *getcwd();
326 extern char *getexecname();
327 extern char *getlogin();
328 extern int getopt();
329 extern char *optarg;
330 extern int optind, opterr, optopt;
331 extern char *getpass();
332 extern char *getpassphrase();
333 extern int getpw();
334 extern int isatty();
335 extern void *memalign();
336 extern char *ttyname();
337 extern char *mkdtemp();
338 
339 #if defined(_LONGLONG_TYPE)
340 extern char *lltostr();
341 extern char *ulltostr();
342 #endif  /* defined(_LONGLONG_TYPE) */
343 #endif	/* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
344 
345 #endif	/* __STDC__ */
346 
347 #ifdef	__cplusplus
348 }
349 #endif
350 
351 #endif	/* _STDLIB_H */
352