blob: 6ec82aa1c28d140bd9fc000c02a1b24225b873b3 [file] [log] [blame]
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07001/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
casper7c4dcc52006-02-23 04:39:12 -08005 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07007 *
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 */
raf019c3c42008-07-12 22:20:11 -070021
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070022/*
Garrett D'Amoreba3594b2014-08-02 18:23:32 -070023 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
Gary Mills0a1278f2013-10-08 08:27:49 -070024 * Copyright (c) 2013 Gary Mills
25 *
Roger A. Faulkner23a1cce2010-08-12 14:55:22 -070026 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070027 */
28
Theo Schlossnagle5dbfd192013-04-11 04:50:36 +000029/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070031/* Copyright (c) 1988 AT&T */
Marcel Telkab4203d72017-06-14 08:51:35 +020032/* All Rights Reserved */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070033
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070034#ifndef _STDLIB_H
35#define _STDLIB_H
36
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070037#include <iso/stdlib_iso.h>
38#include <iso/stdlib_c99.h>
Robert Mustacchifc2512c2016-03-28 19:43:25 -070039#include <iso/stdlib_c11.h>
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070040
41#if defined(__EXTENSIONS__) || defined(_XPG4)
42#include <sys/wait.h>
43#endif
44
45/*
46 * Allow global visibility for symbols defined in
47 * C++ "std" namespace in <iso/stdlib_iso.h>.
48 */
49#if __cplusplus >= 199711L
50using std::div_t;
51using std::ldiv_t;
52using std::size_t;
53using std::abort;
54using std::abs;
55using std::atexit;
56using std::atof;
57using std::atoi;
58using std::atol;
59using std::bsearch;
60using std::calloc;
61using std::div;
62using std::exit;
63using std::free;
64using std::getenv;
65using std::labs;
66using std::ldiv;
67using std::malloc;
68using std::mblen;
69using std::mbstowcs;
70using std::mbtowc;
71using std::qsort;
72using std::rand;
73using std::realloc;
74using std::srand;
75using std::strtod;
76using std::strtol;
77using std::strtoul;
78using std::system;
79using std::wcstombs;
80using std::wctomb;
81#endif
82
Aurélien Larcher0df48812018-05-21 18:35:40 +020083/*
84 * Allow global visibility for symbols defined in
85 * C++ "std" namespace in <iso/stdlib_c11.h>.
86 */
87#if __cplusplus >= 201103L
88using std::at_quick_exit;
89using std::quick_exit;
90#endif
91#if __cplusplus >= 201703L
92using std::aligned_alloc;
93#endif
94
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070095#ifdef __cplusplus
96extern "C" {
97#endif
98
99#ifndef _UID_T
100#define _UID_T
casperf48205b2007-05-25 05:43:42 -0700101typedef unsigned int uid_t; /* UID type */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700102#endif /* !_UID_T */
103
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700104/* large file compilation environment setup */
105#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
106
107#ifdef __PRAGMA_REDEFINE_EXTNAME
108#pragma redefine_extname mkstemp mkstemp64
casper7c4dcc52006-02-23 04:39:12 -0800109#pragma redefine_extname mkstemps mkstemps64
Mohamed A. Khalfella90553fa2015-06-06 11:35:01 +0300110#pragma redefine_extname mkostemp mkostemp64
111#pragma redefine_extname mkostemps mkostemps64
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700112#else /* __PRAGMA_REDEFINE_EXTNAME */
113#define mkstemp mkstemp64
casper7c4dcc52006-02-23 04:39:12 -0800114#define mkstemps mkstemps64
Mohamed A. Khalfella90553fa2015-06-06 11:35:01 +0300115#define mkostemp mkostemp64
116#define mkostemps mkostemps64
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700117#endif /* __PRAGMA_REDEFINE_EXTNAME */
118
119#endif /* _FILE_OFFSET_BITS == 64 */
120
121/* In the LP64 compilation environment, all APIs are already large file */
122#if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
123
124#ifdef __PRAGMA_REDEFINE_EXTNAME
125#pragma redefine_extname mkstemp64 mkstemp
casper7c4dcc52006-02-23 04:39:12 -0800126#pragma redefine_extname mkstemps64 mkstemps
Mohamed A. Khalfella90553fa2015-06-06 11:35:01 +0300127#pragma redefine_extname mkostemp64 mkostemp
128#pragma redefine_extname mkostemps64 mkostemps
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700129#else /* __PRAGMA_REDEFINE_EXTNAME */
130#define mkstemp64 mkstemp
casper7c4dcc52006-02-23 04:39:12 -0800131#define mkstemps64 mkstemps
Mohamed A. Khalfella90553fa2015-06-06 11:35:01 +0300132#define mkostemp64 mkostemp
133#define mkostemps64 mkostemps
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700134#endif /* __PRAGMA_REDEFINE_EXTNAME */
135
136#endif /* _LP64 && _LARGEFILE64_SOURCE */
137
138#if defined(__EXTENSIONS__) || \
139 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
140 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
141extern int rand_r(unsigned int *);
142#endif
143
144extern void _exithandle(void);
145
146#if defined(__EXTENSIONS__) || \
147 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
148 defined(_XPG4)
149extern double drand48(void);
150extern double erand48(unsigned short *);
151extern long jrand48(unsigned short *);
152extern void lcong48(unsigned short *);
153extern long lrand48(void);
154extern long mrand48(void);
155extern long nrand48(unsigned short *);
156extern unsigned short *seed48(unsigned short *);
157extern void srand48(long);
158extern int putenv(char *);
159extern void setkey(const char *);
160#endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
161
162/*
163 * swab() has historically been in <stdlib.h> as delivered from AT&T
164 * and continues to be visible in the default compilation environment.
165 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
166 * in <unistd.h>. As a result, with respect to X/Open namespace the
167 * swab() declaration in this header is only visible for the XPG3
168 * environment.
169 */
170#if (defined(__EXTENSIONS__) || \
171 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
172 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
173#ifndef _SSIZE_T
174#define _SSIZE_T
175#if defined(_LP64) || defined(_I32LPx)
176typedef long ssize_t; /* size of something in bytes or -1 */
177#else
178typedef int ssize_t; /* (historical version) */
179#endif
180#endif /* !_SSIZE_T */
181
182extern void swab(const char *, char *, ssize_t);
183#endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
184
185#if defined(__EXTENSIONS__) || \
186 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
187 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
188extern int mkstemp(char *);
casper4e9cef62006-03-28 10:51:20 -0800189#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
casper7c4dcc52006-02-23 04:39:12 -0800190extern int mkstemps(char *, int);
casper4e9cef62006-03-28 10:51:20 -0800191#endif
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700192#endif /* defined(__EXTENSIONS__) ... */
193
194#if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
195 !defined(__PRAGMA_REDEFINE_EXTNAME))
196extern int mkstemp64(char *);
casper4e9cef62006-03-28 10:51:20 -0800197#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
casper7c4dcc52006-02-23 04:39:12 -0800198extern int mkstemps64(char *, int);
casper4e9cef62006-03-28 10:51:20 -0800199#endif
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700200#endif /* _LARGEFILE64_SOURCE... */
201
Mohamed A. Khalfella90553fa2015-06-06 11:35:01 +0300202#if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
203extern char *mkdtemp(char *);
204#endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */
205
206#if !defined(_STRICT_SYMBOLS)
207extern int mkostemp(char *, int);
208extern int mkostemps(char *, int, int);
209#if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
210 !defined(__PRAGMA_REDEFINE_EXTNAME))
211extern int mkostemp64(char *, int);
212extern int mkostemps64(char *, int, int);
213#endif /* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */
214#endif /* !defined(_STRICT_SYMBOLS) */
215
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700216#if defined(__EXTENSIONS__) || \
217 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
218 defined(_XPG4_2)
219extern long a64l(const char *);
220extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
221extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
222extern char *gcvt(double, int, char *);
223extern int getsubopt(char **, char *const *, char **);
224extern int grantpt(int);
225extern char *initstate(unsigned, char *, size_t);
226extern char *l64a(long);
227extern char *mktemp(char *);
228extern char *ptsname(int);
229extern long random(void);
230extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
231extern char *setstate(const char *);
232extern void srandom(unsigned);
233extern int unlockpt(int);
234/* Marked LEGACY in SUSv2 and removed in SUSv3 */
235#if !defined(_XPG6) || defined(__EXTENSIONS__)
236extern int ttyslot(void);
237extern void *valloc(size_t);
238#endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
239#endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
240
241#if defined(__EXTENSIONS__) || \
242 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
243 defined(_XPG6)
raf019c3c42008-07-12 22:20:11 -0700244extern int posix_memalign(void **, size_t, size_t);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700245extern int posix_openpt(int);
246extern int setenv(const char *, const char *, int);
247extern int unsetenv(const char *);
248#endif
249
250#if defined(__EXTENSIONS__) || \
251 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
Roger A. Faulkner23a1cce2010-08-12 14:55:22 -0700252extern char *canonicalize_file_name(const char *);
253extern int clearenv(void);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700254extern void closefrom(int);
Vladimir Kotal44991a12009-09-15 20:20:20 +0200255extern int daemon(int, int);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700256extern int dup2(int, int);
Theo Schlossnagle5dbfd192013-04-11 04:50:36 +0000257extern int dup3(int, int, int);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700258extern int fdwalk(int (*)(void *, int), void *);
259extern char *qecvt(long double, int, int *, int *);
260extern char *qfcvt(long double, int, int *, int *);
261extern char *qgcvt(long double, int, char *);
262extern char *getcwd(char *, size_t);
263extern const char *getexecname(void);
Gary Mills0a1278f2013-10-08 08:27:49 -0700264
265#ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */
266#define __GETLOGIN_DEFINED
267#ifndef __USE_LEGACY_LOGNAME__
268#ifdef __PRAGMA_REDEFINE_EXTNAME
269#pragma redefine_extname getlogin getloginx
270#else /* __PRAGMA_REDEFINE_EXTNAME */
271extern char *getloginx(void);
272#define getlogin getloginx
273#endif /* __PRAGMA_REDEFINE_EXTNAME */
274#endif /* __USE_LEGACY_LOGNAME__ */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700275extern char *getlogin(void);
Gary Mills0a1278f2013-10-08 08:27:49 -0700276#endif /* __GETLOGIN_DEFINED */
277
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700278extern int getopt(int, char *const *, const char *);
279extern char *optarg;
280extern int optind, opterr, optopt;
281extern char *getpass(const char *);
282extern char *getpassphrase(const char *);
283extern int getpw(uid_t, char *);
284extern int isatty(int);
285extern void *memalign(size_t, size_t);
286extern char *ttyname(int);
casper7c4dcc52006-02-23 04:39:12 -0800287extern char *mkdtemp(char *);
Roger A. Faulkner23a1cce2010-08-12 14:55:22 -0700288extern const char *getprogname(void);
289extern void setprogname(const char *);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700290
291#if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
292extern char *lltostr(long long, char *);
293extern char *ulltostr(unsigned long long, char *);
294#endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
295
296#endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
297
Robert Mustacchi9d127952015-04-07 09:59:42 -0700298/* OpenBSD compatibility functions */
299#if !defined(_STRICT_SYMBOLS)
300
301#include <inttypes.h>
302extern uint32_t arc4random(void);
303extern void arc4random_buf(void *, size_t);
304extern uint32_t arc4random_uniform(uint32_t);
Yuri Pankovf1cdbd32017-07-28 14:44:18 +0300305extern void freezero(void *, size_t);
Yuri Pankov45851302017-06-12 20:16:28 -0700306extern void *reallocarray(void *, size_t, size_t);
Yuri Pankovf1cdbd32017-07-28 14:44:18 +0300307extern void *recallocarray(void *, size_t, size_t, size_t);
Yuri Pankov45851302017-06-12 20:16:28 -0700308extern long long strtonum(const char *, long long, long long, const char **);
Robert Mustacchi9d127952015-04-07 09:59:42 -0700309
310#endif /* !_STRICT_SYBMOLS */
311
312
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700313#ifdef __cplusplus
314}
315#endif
316
317#endif /* _STDLIB_H */