stdlib.h revision 1475:0c7070c5774f
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
47using std::div_t;
48using std::ldiv_t;
49using std::size_t;
50using std::abort;
51using std::abs;
52using std::atexit;
53using std::atof;
54using std::atoi;
55using std::atol;
56using std::bsearch;
57using std::calloc;
58using std::div;
59using std::exit;
60using std::free;
61using std::getenv;
62using std::labs;
63using std::ldiv;
64using std::malloc;
65using std::mblen;
66using std::mbstowcs;
67using std::mbtowc;
68using std::qsort;
69using std::rand;
70using std::realloc;
71using std::srand;
72using std::strtod;
73using std::strtol;
74using std::strtoul;
75using std::system;
76using std::wcstombs;
77using std::wctomb;
78#endif
79
80#ifdef	__cplusplus
81extern "C" {
82#endif
83
84#ifndef _UID_T
85#define	_UID_T
86#if defined(_LP64) || defined(_I32LPx)
87typedef	int	uid_t;			/* UID type		*/
88#else
89typedef 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)
124extern int rand_r(unsigned int *);
125#endif
126
127extern void _exithandle(void);
128
129#if defined(__EXTENSIONS__) || \
130	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
131	defined(_XPG4)
132extern double drand48(void);
133extern double erand48(unsigned short *);
134extern long jrand48(unsigned short *);
135extern void lcong48(unsigned short *);
136extern long lrand48(void);
137extern long mrand48(void);
138extern long nrand48(unsigned short *);
139extern unsigned short *seed48(unsigned short *);
140extern void srand48(long);
141extern int putenv(char *);
142extern 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)
159typedef long	ssize_t;	/* size of something in bytes or -1 */
160#else
161typedef int	ssize_t;	/* (historical version) */
162#endif
163#endif	/* !_SSIZE_T */
164
165extern 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)
171extern int	mkstemp(char *);
172extern int	mkstemps(char *, int);
173#endif /* defined(__EXTENSIONS__) ... */
174
175#if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
176	    !defined(__PRAGMA_REDEFINE_EXTNAME))
177extern int	mkstemp64(char *);
178extern int	mkstemps64(char *, int);
179#endif	/* _LARGEFILE64_SOURCE... */
180
181#if defined(__EXTENSIONS__) || \
182	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
183	defined(_XPG4_2)
184extern long a64l(const char *);
185extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
186extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
187extern char *gcvt(double, int, char *);
188extern int getsubopt(char **, char *const *, char **);
189extern int  grantpt(int);
190extern char *initstate(unsigned, char *, size_t);
191extern char *l64a(long);
192extern char *mktemp(char *);
193extern char *ptsname(int);
194extern long random(void);
195extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
196extern char *setstate(const char *);
197extern void srandom(unsigned);
198extern int  unlockpt(int);
199/* Marked LEGACY in SUSv2 and removed in SUSv3 */
200#if !defined(_XPG6) || defined(__EXTENSIONS__)
201extern int ttyslot(void);
202extern 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)
209extern int posix_openpt(int);
210extern int setenv(const char *, const char *, int);
211extern int unsetenv(const char *);
212#endif
213
214#if defined(__EXTENSIONS__) || \
215	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
216extern void closefrom(int);
217extern int dup2(int, int);
218extern int fdwalk(int (*)(void *, int), void *);
219extern char *qecvt(long double, int, int *, int *);
220extern char *qfcvt(long double, int, int *, int *);
221extern char *qgcvt(long double, int, char *);
222extern char *getcwd(char *, size_t);
223extern const char *getexecname(void);
224extern char *getlogin(void);
225extern int getopt(int, char *const *, const char *);
226extern char *optarg;
227extern int optind, opterr, optopt;
228extern char *getpass(const char *);
229extern char *getpassphrase(const char *);
230extern int getpw(uid_t, char *);
231extern int isatty(int);
232extern void *memalign(size_t, size_t);
233extern char *ttyname(int);
234extern char *mkdtemp(char *);
235
236#if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
237extern char *lltostr(long long, char *);
238extern char *ulltostr(unsigned long long, char *);
239#endif	/* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
240
241#endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
242
243#else /* not __STDC__ */
244
245#if defined(__EXTENSIONS__) || !defined(_XOPEN_OR_POSIX) || \
246	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
247extern int rand_r();
248#endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT) ... */
249
250extern void _exithandle();
251
252#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || defined(_XPG4)
253extern double drand48();
254extern double erand48();
255extern long jrand48();
256extern void lcong48();
257extern long lrand48();
258extern long mrand48();
259extern long nrand48();
260extern unsigned short *seed48();
261extern void srand48();
262extern int putenv();
263extern void setkey();
264#endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
265
266#if (defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)) && \
267	(!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
268extern void swab();
269#endif
270
271#if defined(__EXTENSIONS__) || \
272	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
273	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
274extern int	mkstemp();
275extern int	mkstemps();
276#endif	/* defined(__EXTENSIONS__) ... */
277
278#if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
279	    !defined(__PRAGMA_REDEFINE_EXTNAME))
280extern int	mkstemp64();
281extern int	mkstemps64();
282#endif	/* _LARGEFILE64_SOURCE... */
283
284#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
285extern long a64l();
286extern char *ecvt();
287extern char *fcvt();
288extern char *gcvt();
289extern int getsubopt();
290extern int grantpt();
291extern char *initstate();
292extern char *l64a();
293extern char *mktemp();
294extern char *ptsname();
295extern long random();
296extern char *realpath();
297extern char *setstate();
298extern void srandom();
299/* Marked LEGACY in SUSv2 and removed in SUSv3 */
300#if !defined(_XPG6) || defined(__EXTENSIONS__)
301extern int ttyslot();
302extern void *valloc();
303#endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
304#endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
305
306#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6)
307extern int posix_openpt();
308extern int setenv();
309extern int unsetenv();
310#endif
311
312#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
313extern void closefrom();
314extern int dup2();
315extern int fdwalk();
316extern char *qecvt();
317extern char *qfcvt();
318extern char *qgcvt();
319extern char *getcwd();
320extern char *getexecname();
321extern char *getlogin();
322extern int getopt();
323extern char *optarg;
324extern int optind, opterr, optopt;
325extern char *getpass();
326extern char *getpassphrase();
327extern int getpw();
328extern int isatty();
329extern void *memalign();
330extern char *ttyname();
331extern char *mkdtemp();
332
333#if defined(_LONGLONG_TYPE)
334extern char *lltostr();
335extern char *ulltostr();
336#endif  /* defined(_LONGLONG_TYPE) */
337#endif	/* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
338
339#endif	/* __STDC__ */
340
341#ifdef	__cplusplus
342}
343#endif
344
345#endif	/* _STDLIB_H */
346