Unleashed v1.4
[unleashed.git] / include / stdlib.h
blob0b19c7b1eb420a9813bd02acad85e09037a5244c
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>
40 #include <inttypes.h>
43 * Allow global visibility for symbols defined in
44 * C++ "std" namespace in <iso/stdlib_iso.h>.
46 #if __cplusplus >= 199711L
47 using std::div_t;
48 using std::ldiv_t;
49 using std::size_t;
50 using std::abort;
51 using std::abs;
52 using std::atexit;
53 using std::atof;
54 using std::atoi;
55 using std::atol;
56 using std::bsearch;
57 using std::calloc;
58 using std::div;
59 using std::exit;
60 using std::free;
61 using std::getenv;
62 using std::labs;
63 using std::ldiv;
64 using std::malloc;
65 using std::mblen;
66 using std::mbstowcs;
67 using std::mbtowc;
68 using std::qsort;
69 using std::rand;
70 using std::realloc;
71 using std::srand;
72 using std::strtod;
73 using std::strtol;
74 using std::strtoul;
75 using std::system;
76 using std::wcstombs;
77 using std::wctomb;
78 #endif
81 * Allow global visibility for symbols defined in
82 * C++ "std" namespace in <iso/stdlib_c11.h>.
84 #if __cplusplus >= 201103L
85 using std::at_quick_exit;
86 using std::quick_exit;
87 #endif
88 #if __cplusplus >= 201703L
89 using std::aligned_alloc;
90 #endif
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
96 #ifndef _UID_T
97 #define _UID_T
98 typedef uint32_t uid_t; /* UID type */
99 #endif /* !_UID_T */
101 extern int rand_r(unsigned int *);
103 extern void _exithandle(void);
105 #if defined(__EXTENSIONS__) || \
106 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
107 defined(_XPG4)
108 extern double drand48(void);
109 extern double erand48(unsigned short *);
110 extern long jrand48(unsigned short *);
111 extern void lcong48(unsigned short *);
112 extern long lrand48(void);
113 extern long mrand48(void);
114 extern long nrand48(unsigned short *);
115 extern unsigned short *seed48(unsigned short *);
116 extern void srand48(long);
117 extern int putenv(char *);
118 extern void setkey(const char *);
119 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
122 * swab() has historically been in <stdlib.h> as delivered from AT&T
123 * and continues to be visible in the default compilation environment.
124 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
125 * in <unistd.h>. As a result, with respect to X/Open namespace the
126 * swab() declaration in this header is only visible for the XPG3
127 * environment.
129 #if (defined(__EXTENSIONS__) || \
130 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
131 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
132 #ifndef _SSIZE_T
133 #define _SSIZE_T
134 #if defined(_LP64) || defined(_I32LPx)
135 typedef long ssize_t; /* size of something in bytes or -1 */
136 #else
137 typedef int ssize_t; /* (historical version) */
138 #endif
139 #endif /* !_SSIZE_T */
141 extern void swab(const char *, char *, ssize_t);
142 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
144 #if defined(__EXTENSIONS__) || \
145 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
146 extern int mkstemp(char *);
147 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
148 extern int mkstemps(char *, int);
149 #endif
150 #endif /* defined(__EXTENSIONS__) ... */
152 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
153 extern char *mkdtemp(char *);
154 #endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
156 #if !defined(_STRICT_SYMBOLS)
157 extern int mkostemp(char *, int);
158 extern int mkostemps(char *, int, int);
159 #endif /* !defined(_STRICT_SYMBOLS) */
161 #if defined(__EXTENSIONS__) || \
162 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
163 defined(_XPG4_2)
164 extern long a64l(const char *);
165 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
166 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
167 extern char *gcvt(double, int, char *);
168 extern int getsubopt(char **, char *const *, char **);
169 extern int grantpt(int);
170 extern char *initstate(unsigned, char *, size_t);
171 extern char *l64a(long);
172 extern char *mktemp(char *);
173 extern char *ptsname(int);
174 extern long random(void);
175 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
176 extern char *setstate(const char *);
177 extern void srandom(unsigned);
178 extern int unlockpt(int);
179 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
180 #if !defined(_XPG6) || defined(__EXTENSIONS__)
181 extern int ttyslot(void);
182 extern void *valloc(size_t);
183 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
184 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
186 #if defined(__EXTENSIONS__) || \
187 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
188 defined(_XPG6)
189 extern int posix_memalign(void **, size_t, size_t);
190 extern int posix_openpt(int);
191 extern int setenv(const char *, const char *, int);
192 extern int unsetenv(const char *);
193 #endif
195 #if defined(__EXTENSIONS__) || \
196 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
197 extern char *canonicalize_file_name(const char *);
198 extern int clearenv(void);
199 extern void closefrom(int);
200 extern int daemon(int, int);
201 extern int dup2(int, int);
202 extern int dup3(int, int, int);
203 extern int fdwalk(int (*)(void *, int), void *);
204 extern char *qecvt(long double, int, int *, int *);
205 extern char *qfcvt(long double, int, int *, int *);
206 extern char *qgcvt(long double, int, char *);
207 extern char *getcwd(char *, size_t);
208 extern const char *getexecname(void);
210 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */
211 extern char *getlogin(void);
212 #endif /* __GETLOGIN_DEFINED */
214 extern int getopt(int, char *const *, const char *);
215 extern char *optarg;
216 extern int optind, opterr, optopt;
217 extern char *getpass(const char *);
218 extern char *getpassphrase(const char *);
219 extern int isatty(int);
220 extern void *memalign(size_t, size_t);
221 extern char *ttyname(int);
222 extern char *mkdtemp(char *);
223 extern const char *getprogname(void);
224 extern void setprogname(const char *);
226 #if __UNLEASHED_VISIBLE
227 extern char *lltostr(long long, char *);
228 extern char *ulltostr(unsigned long long, char *);
229 #endif
231 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
233 /* OpenBSD compatibility functions */
234 #if __UNLEASHED_VISIBLE
236 extern uint32_t arc4random(void);
237 extern void arc4random_buf(void *, size_t);
238 extern uint32_t arc4random_uniform(uint32_t);
239 long long strtonum(const char *, long long, long long, const char **);
241 #endif /* __UNLEASHED_VISIBLE */
243 #ifdef __cplusplus
245 #endif
247 #endif /* _STDLIB_H */