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