clean up ttyname_r, getlogin_r & remove getloginx
[unleashed.git] / include / stdlib.h
blob5902fe5289a944fcbc024f019de4a63b54ad5c53
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>
41 #if defined(__EXTENSIONS__) || defined(_XPG4)
42 #include <sys/wait.h>
43 #endif
46 * Allow global visibility for symbols defined in
47 * C++ "std" namespace in <iso/stdlib_iso.h>.
49 #if __cplusplus >= 199711L
50 using std::div_t;
51 using std::ldiv_t;
52 using std::size_t;
53 using std::abort;
54 using std::abs;
55 using std::atexit;
56 using std::atof;
57 using std::atoi;
58 using std::atol;
59 using std::bsearch;
60 using std::calloc;
61 using std::div;
62 using std::exit;
63 using std::free;
64 using std::getenv;
65 using std::labs;
66 using std::ldiv;
67 using std::malloc;
68 using std::mblen;
69 using std::mbstowcs;
70 using std::mbtowc;
71 using std::qsort;
72 using std::rand;
73 using std::realloc;
74 using std::srand;
75 using std::strtod;
76 using std::strtol;
77 using std::strtoul;
78 using std::system;
79 using std::wcstombs;
80 using std::wctomb;
81 #endif
84 * Allow global visibility for symbols defined in
85 * C++ "std" namespace in <iso/stdlib_c11.h>.
87 #if __cplusplus >= 201103L
88 using std::at_quick_exit;
89 using std::quick_exit;
90 #endif
91 #if __cplusplus >= 201703L
92 using std::aligned_alloc;
93 #endif
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
99 #ifndef _UID_T
100 #define _UID_T
101 typedef unsigned int uid_t; /* UID type */
102 #endif /* !_UID_T */
104 /* large file compilation environment setup */
105 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
107 #ifdef __PRAGMA_REDEFINE_EXTNAME
108 #pragma redefine_extname mkstemp mkstemp64
109 #pragma redefine_extname mkstemps mkstemps64
110 #pragma redefine_extname mkostemp mkostemp64
111 #pragma redefine_extname mkostemps mkostemps64
112 #else /* __PRAGMA_REDEFINE_EXTNAME */
113 #define mkstemp mkstemp64
114 #define mkstemps mkstemps64
115 #define mkostemp mkostemp64
116 #define mkostemps mkostemps64
117 #endif /* __PRAGMA_REDEFINE_EXTNAME */
119 #endif /* _FILE_OFFSET_BITS == 64 */
121 /* In the LP64 compilation environment, all APIs are already large file */
122 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
124 #ifdef __PRAGMA_REDEFINE_EXTNAME
125 #pragma redefine_extname mkstemp64 mkstemp
126 #pragma redefine_extname mkstemps64 mkstemps
127 #pragma redefine_extname mkostemp64 mkostemp
128 #pragma redefine_extname mkostemps64 mkostemps
129 #else /* __PRAGMA_REDEFINE_EXTNAME */
130 #define mkstemp64 mkstemp
131 #define mkstemps64 mkstemps
132 #define mkostemp64 mkostemp
133 #define mkostemps64 mkostemps
134 #endif /* __PRAGMA_REDEFINE_EXTNAME */
136 #endif /* _LP64 && _LARGEFILE64_SOURCE */
138 extern int rand_r(unsigned int *);
140 extern void _exithandle(void);
142 #if defined(__EXTENSIONS__) || \
143 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
144 defined(_XPG4)
145 extern double drand48(void);
146 extern double erand48(unsigned short *);
147 extern long jrand48(unsigned short *);
148 extern void lcong48(unsigned short *);
149 extern long lrand48(void);
150 extern long mrand48(void);
151 extern long nrand48(unsigned short *);
152 extern unsigned short *seed48(unsigned short *);
153 extern void srand48(long);
154 extern int putenv(char *);
155 extern void setkey(const char *);
156 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
159 * swab() has historically been in <stdlib.h> as delivered from AT&T
160 * and continues to be visible in the default compilation environment.
161 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
162 * in <unistd.h>. As a result, with respect to X/Open namespace the
163 * swab() declaration in this header is only visible for the XPG3
164 * environment.
166 #if (defined(__EXTENSIONS__) || \
167 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
168 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
169 #ifndef _SSIZE_T
170 #define _SSIZE_T
171 #if defined(_LP64) || defined(_I32LPx)
172 typedef long ssize_t; /* size of something in bytes or -1 */
173 #else
174 typedef int ssize_t; /* (historical version) */
175 #endif
176 #endif /* !_SSIZE_T */
178 extern void swab(const char *, char *, ssize_t);
179 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
181 #if defined(__EXTENSIONS__) || \
182 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
183 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
184 extern int mkstemp(char *);
185 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
186 extern int mkstemps(char *, int);
187 #endif
188 #endif /* defined(__EXTENSIONS__) ... */
190 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
191 !defined(__PRAGMA_REDEFINE_EXTNAME))
192 extern int mkstemp64(char *);
193 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
194 extern int mkstemps64(char *, int);
195 #endif
196 #endif /* _LARGEFILE64_SOURCE... */
198 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
199 extern char *mkdtemp(char *);
200 #endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
202 #if !defined(_STRICT_SYMBOLS)
203 extern int mkostemp(char *, int);
204 extern int mkostemps(char *, int, int);
205 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
206 !defined(__PRAGMA_REDEFINE_EXTNAME))
207 extern int mkostemp64(char *, int);
208 extern int mkostemps64(char *, int, int);
209 #endif /* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */
210 #endif /* !defined(_STRICT_SYMBOLS) */
212 #if defined(__EXTENSIONS__) || \
213 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
214 defined(_XPG4_2)
215 extern long a64l(const char *);
216 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
217 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
218 extern char *gcvt(double, int, char *);
219 extern int getsubopt(char **, char *const *, char **);
220 extern int grantpt(int);
221 extern char *initstate(unsigned, char *, size_t);
222 extern char *l64a(long);
223 extern char *mktemp(char *);
224 extern char *ptsname(int);
225 extern long random(void);
226 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
227 extern char *setstate(const char *);
228 extern void srandom(unsigned);
229 extern int unlockpt(int);
230 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
231 #if !defined(_XPG6) || defined(__EXTENSIONS__)
232 extern int ttyslot(void);
233 extern void *valloc(size_t);
234 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
235 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
237 #if defined(__EXTENSIONS__) || \
238 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
239 defined(_XPG6)
240 extern int posix_memalign(void **, size_t, size_t);
241 extern int posix_openpt(int);
242 extern int setenv(const char *, const char *, int);
243 extern int unsetenv(const char *);
244 #endif
246 #if defined(__EXTENSIONS__) || \
247 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
248 extern char *canonicalize_file_name(const char *);
249 extern int clearenv(void);
250 extern void closefrom(int);
251 extern int daemon(int, int);
252 extern int dup2(int, int);
253 extern int dup3(int, int, int);
254 extern int fdwalk(int (*)(void *, int), void *);
255 extern char *qecvt(long double, int, int *, int *);
256 extern char *qfcvt(long double, int, int *, int *);
257 extern char *qgcvt(long double, int, char *);
258 extern char *getcwd(char *, size_t);
259 extern const char *getexecname(void);
261 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */
262 extern char *getlogin(void);
263 #endif /* __GETLOGIN_DEFINED */
265 extern int getopt(int, char *const *, const char *);
266 extern char *optarg;
267 extern int optind, opterr, optopt;
268 extern char *getpass(const char *);
269 extern char *getpassphrase(const char *);
270 extern int isatty(int);
271 extern void *memalign(size_t, size_t);
272 extern char *ttyname(int);
273 extern char *mkdtemp(char *);
274 extern const char *getprogname(void);
275 extern void setprogname(const char *);
277 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
278 extern char *lltostr(long long, char *);
279 extern char *ulltostr(unsigned long long, char *);
280 #endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
282 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
284 /* OpenBSD compatibility functions */
285 #if !defined(_STRICT_SYMBOLS)
287 #include <inttypes.h>
288 extern uint32_t arc4random(void);
289 extern void arc4random_buf(void *, size_t);
290 extern uint32_t arc4random_uniform(uint32_t);
291 long long strtonum(const char *, long long, long long, const char **);
293 #endif /* !_STRICT_SYBMOLS */
295 #ifdef __cplusplus
297 #endif
299 #endif /* _STDLIB_H */