FEATURES: add notes about compilation env changes
[unleashed.git] / include / stdlib.h
blobae55be992210feb61ea27682c181ba54c1eea31c
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 2013 Gary Mills
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
31 /* Copyright (c) 1988 AT&T */
32 /* All Rights Reserved */
34 #ifndef _STDLIB_H
35 #define _STDLIB_H
37 #include <iso/stdlib_iso.h>
38 #include <iso/stdlib_c99.h>
39 #include <iso/stdlib_c11.h>
42 * Allow global visibility for symbols defined in
43 * C++ "std" namespace in <iso/stdlib_iso.h>.
45 #if __cplusplus >= 199711L
46 using std::div_t;
47 using std::ldiv_t;
48 using std::size_t;
49 using std::abort;
50 using std::abs;
51 using std::atexit;
52 using std::atof;
53 using std::atoi;
54 using std::atol;
55 using std::bsearch;
56 using std::calloc;
57 using std::div;
58 using std::exit;
59 using std::free;
60 using std::getenv;
61 using std::labs;
62 using std::ldiv;
63 using std::malloc;
64 using std::mblen;
65 using std::mbstowcs;
66 using std::mbtowc;
67 using std::qsort;
68 using std::rand;
69 using std::realloc;
70 using std::srand;
71 using std::strtod;
72 using std::strtol;
73 using std::strtoul;
74 using std::system;
75 using std::wcstombs;
76 using std::wctomb;
77 #endif
80 * Allow global visibility for symbols defined in
81 * C++ "std" namespace in <iso/stdlib_c11.h>.
83 #if __cplusplus >= 201103L
84 using std::at_quick_exit;
85 using std::quick_exit;
86 #endif
87 #if __cplusplus >= 201703L
88 using std::aligned_alloc;
89 #endif
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
95 #ifndef _UID_T
96 #define _UID_T
97 typedef unsigned int uid_t; /* UID type */
98 #endif /* !_UID_T */
100 /* large file compilation environment setup */
101 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
103 #ifdef __PRAGMA_REDEFINE_EXTNAME
104 #pragma redefine_extname mkstemp mkstemp64
105 #pragma redefine_extname mkstemps mkstemps64
106 #pragma redefine_extname mkostemp mkostemp64
107 #pragma redefine_extname mkostemps mkostemps64
108 #else /* __PRAGMA_REDEFINE_EXTNAME */
109 #define mkstemp mkstemp64
110 #define mkstemps mkstemps64
111 #define mkostemp mkostemp64
112 #define mkostemps mkostemps64
113 #endif /* __PRAGMA_REDEFINE_EXTNAME */
115 #endif /* _FILE_OFFSET_BITS == 64 */
117 /* In the LP64 compilation environment, all APIs are already large file */
118 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
120 #ifdef __PRAGMA_REDEFINE_EXTNAME
121 #pragma redefine_extname mkstemp64 mkstemp
122 #pragma redefine_extname mkstemps64 mkstemps
123 #pragma redefine_extname mkostemp64 mkostemp
124 #pragma redefine_extname mkostemps64 mkostemps
125 #else /* __PRAGMA_REDEFINE_EXTNAME */
126 #define mkstemp64 mkstemp
127 #define mkstemps64 mkstemps
128 #define mkostemp64 mkostemp
129 #define mkostemps64 mkostemps
130 #endif /* __PRAGMA_REDEFINE_EXTNAME */
132 #endif /* _LP64 && _LARGEFILE64_SOURCE */
134 extern int rand_r(unsigned int *);
136 extern void _exithandle(void);
138 #if defined(__EXTENSIONS__) || \
139 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
140 defined(_XPG4)
141 extern double drand48(void);
142 extern double erand48(unsigned short *);
143 extern long jrand48(unsigned short *);
144 extern void lcong48(unsigned short *);
145 extern long lrand48(void);
146 extern long mrand48(void);
147 extern long nrand48(unsigned short *);
148 extern unsigned short *seed48(unsigned short *);
149 extern void srand48(long);
150 extern int putenv(char *);
151 extern void setkey(const char *);
152 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
155 * swab() has historically been in <stdlib.h> as delivered from AT&T
156 * and continues to be visible in the default compilation environment.
157 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
158 * in <unistd.h>. As a result, with respect to X/Open namespace the
159 * swab() declaration in this header is only visible for the XPG3
160 * environment.
162 #if (defined(__EXTENSIONS__) || \
163 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
164 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
165 #ifndef _SSIZE_T
166 #define _SSIZE_T
167 #if defined(_LP64) || defined(_I32LPx)
168 typedef long ssize_t; /* size of something in bytes or -1 */
169 #else
170 typedef int ssize_t; /* (historical version) */
171 #endif
172 #endif /* !_SSIZE_T */
174 extern void swab(const char *, char *, ssize_t);
175 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
177 #if defined(__EXTENSIONS__) || \
178 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
179 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
180 extern int mkstemp(char *);
181 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
182 extern int mkstemps(char *, int);
183 #endif
184 #endif /* defined(__EXTENSIONS__) ... */
186 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
187 !defined(__PRAGMA_REDEFINE_EXTNAME))
188 extern int mkstemp64(char *);
189 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
190 extern int mkstemps64(char *, int);
191 #endif
192 #endif /* _LARGEFILE64_SOURCE... */
194 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
195 extern char *mkdtemp(char *);
196 #endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
198 #if !defined(_STRICT_SYMBOLS)
199 extern int mkostemp(char *, int);
200 extern int mkostemps(char *, int, int);
201 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
202 !defined(__PRAGMA_REDEFINE_EXTNAME))
203 extern int mkostemp64(char *, int);
204 extern int mkostemps64(char *, int, int);
205 #endif /* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */
206 #endif /* !defined(_STRICT_SYMBOLS) */
208 #if defined(__EXTENSIONS__) || \
209 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
210 defined(_XPG4_2)
211 extern long a64l(const char *);
212 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
213 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
214 extern char *gcvt(double, int, char *);
215 extern int getsubopt(char **, char *const *, char **);
216 extern int grantpt(int);
217 extern char *initstate(unsigned, char *, size_t);
218 extern char *l64a(long);
219 extern char *mktemp(char *);
220 extern char *ptsname(int);
221 extern long random(void);
222 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
223 extern char *setstate(const char *);
224 extern void srandom(unsigned);
225 extern int unlockpt(int);
226 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
227 #if !defined(_XPG6) || defined(__EXTENSIONS__)
228 extern int ttyslot(void);
229 extern void *valloc(size_t);
230 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
231 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
233 #if defined(__EXTENSIONS__) || \
234 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
235 defined(_XPG6)
236 extern int posix_memalign(void **, size_t, size_t);
237 extern int posix_openpt(int);
238 extern int setenv(const char *, const char *, int);
239 extern int unsetenv(const char *);
240 #endif
242 #if defined(__EXTENSIONS__) || \
243 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
244 extern char *canonicalize_file_name(const char *);
245 extern int clearenv(void);
246 extern void closefrom(int);
247 extern int daemon(int, int);
248 extern int dup2(int, int);
249 extern int dup3(int, int, int);
250 extern int fdwalk(int (*)(void *, int), void *);
251 extern char *qecvt(long double, int, int *, int *);
252 extern char *qfcvt(long double, int, int *, int *);
253 extern char *qgcvt(long double, int, char *);
254 extern char *getcwd(char *, size_t);
255 extern const char *getexecname(void);
257 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */
258 extern char *getlogin(void);
259 #endif /* __GETLOGIN_DEFINED */
261 extern int getopt(int, char *const *, const char *);
262 extern char *optarg;
263 extern int optind, opterr, optopt;
264 extern char *getpass(const char *);
265 extern char *getpassphrase(const char *);
266 extern int isatty(int);
267 extern void *memalign(size_t, size_t);
268 extern char *ttyname(int);
269 extern char *mkdtemp(char *);
270 extern const char *getprogname(void);
271 extern void setprogname(const char *);
273 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
274 extern char *lltostr(long long, char *);
275 extern char *ulltostr(unsigned long long, char *);
276 #endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
278 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
280 /* OpenBSD compatibility functions */
281 #if !defined(_STRICT_SYMBOLS)
283 #include <inttypes.h>
284 extern uint32_t arc4random(void);
285 extern void arc4random_buf(void *, size_t);
286 extern uint32_t arc4random_uniform(uint32_t);
287 long long strtonum(const char *, long long, long long, const char **);
289 #endif /* !_STRICT_SYBMOLS */
291 #ifdef __cplusplus
293 #endif
295 #endif /* _STDLIB_H */