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