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 /* 23 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24 * Copyright (c) 2013 Gary Mills 25 * 26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 27 */ 28 29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */ 30 31 /* Copyright (c) 1988 AT&T */ 32 /* All Rights Reserved */ 33 34 #ifndef _STDLIB_H 35 #define _STDLIB_H 36 37 #include <iso/stdlib_iso.h> 38 #include <iso/stdlib_c99.h> 39 #include <iso/stdlib_c11.h> 40 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 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 82 83 #ifdef __cplusplus 84 extern "C" { 85 #endif 86 87 #ifndef _UID_T 88 #define _UID_T 89 typedef unsigned int uid_t; /* UID type */ 90 #endif /* !_UID_T */ 91 92 /* large file compilation environment setup */ 93 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 94 95 #ifdef __PRAGMA_REDEFINE_EXTNAME 96 #pragma redefine_extname mkstemp mkstemp64 97 #pragma redefine_extname mkstemps mkstemps64 98 #pragma redefine_extname mkostemp mkostemp64 99 #pragma redefine_extname mkostemps mkostemps64 100 #else /* __PRAGMA_REDEFINE_EXTNAME */ 101 #define mkstemp mkstemp64 102 #define mkstemps mkstemps64 103 #define mkostemp mkostemp64 104 #define mkostemps mkostemps64 105 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 106 107 #endif /* _FILE_OFFSET_BITS == 64 */ 108 109 /* In the LP64 compilation environment, all APIs are already large file */ 110 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 111 112 #ifdef __PRAGMA_REDEFINE_EXTNAME 113 #pragma redefine_extname mkstemp64 mkstemp 114 #pragma redefine_extname mkstemps64 mkstemps 115 #pragma redefine_extname mkostemp64 mkostemp 116 #pragma redefine_extname mkostemps64 mkostemps 117 #else /* __PRAGMA_REDEFINE_EXTNAME */ 118 #define mkstemp64 mkstemp 119 #define mkstemps64 mkstemps 120 #define mkostemp64 mkostemp 121 #define mkostemps64 mkostemps 122 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 123 124 #endif /* _LP64 && _LARGEFILE64_SOURCE */ 125 126 #if defined(__EXTENSIONS__) || \ 127 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 128 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT) 129 extern int rand_r(unsigned int *); 130 #endif 131 132 extern void _exithandle(void); 133 134 #if defined(__EXTENSIONS__) || \ 135 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 136 defined(_XPG4) 137 extern double drand48(void); 138 extern double erand48(unsigned short *); 139 extern long jrand48(unsigned short *); 140 extern void lcong48(unsigned short *); 141 extern long lrand48(void); 142 extern long mrand48(void); 143 extern long nrand48(unsigned short *); 144 extern unsigned short *seed48(unsigned short *); 145 extern void srand48(long); 146 extern int putenv(char *); 147 extern void setkey(const char *); 148 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 149 150 /* 151 * swab() has historically been in <stdlib.h> as delivered from AT&T 152 * and continues to be visible in the default compilation environment. 153 * As of Issue 4 of the X/Open Portability Guides, swab() was declared 154 * in <unistd.h>. As a result, with respect to X/Open namespace the 155 * swab() declaration in this header is only visible for the XPG3 156 * environment. 157 */ 158 #if (defined(__EXTENSIONS__) || \ 159 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \ 160 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4))) 161 #ifndef _SSIZE_T 162 #define _SSIZE_T 163 #if defined(_LP64) || defined(_I32LPx) 164 typedef long ssize_t; /* size of something in bytes or -1 */ 165 #else 166 typedef int ssize_t; /* (historical version) */ 167 #endif 168 #endif /* !_SSIZE_T */ 169 170 extern void swab(const char *, char *, ssize_t); 171 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 172 173 #if defined(__EXTENSIONS__) || \ 174 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 175 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) 176 extern int mkstemp(char *); 177 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 178 extern int mkstemps(char *, int); 179 #endif 180 #endif /* defined(__EXTENSIONS__) ... */ 181 182 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 183 !defined(__PRAGMA_REDEFINE_EXTNAME)) 184 extern int mkstemp64(char *); 185 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 186 extern int mkstemps64(char *, int); 187 #endif 188 #endif /* _LARGEFILE64_SOURCE... */ 189 190 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7) 191 extern char *mkdtemp(char *); 192 #endif /* !defined(_STRICT_SYMBOLS) || defined(_XPG7) */ 193 194 #if !defined(_STRICT_SYMBOLS) 195 extern int mkostemp(char *, int); 196 extern int mkostemps(char *, int, int); 197 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 198 !defined(__PRAGMA_REDEFINE_EXTNAME)) 199 extern int mkostemp64(char *, int); 200 extern int mkostemps64(char *, int, int); 201 #endif /* defined(_LARGEFILE64_SOURCE) || !((_FILE_OFFSET_BITS == 64) ... */ 202 #endif /* !defined(_STRICT_SYMBOLS) */ 203 204 #if defined(__EXTENSIONS__) || \ 205 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 206 defined(_XPG4_2) 207 extern long a64l(const char *); 208 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD); 209 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD); 210 extern char *gcvt(double, int, char *); 211 extern int getsubopt(char **, char *const *, char **); 212 extern int grantpt(int); 213 extern char *initstate(unsigned, char *, size_t); 214 extern char *l64a(long); 215 extern char *mktemp(char *); 216 extern char *ptsname(int); 217 extern long random(void); 218 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD); 219 extern char *setstate(const char *); 220 extern void srandom(unsigned); 221 extern int unlockpt(int); 222 /* Marked LEGACY in SUSv2 and removed in SUSv3 */ 223 #if !defined(_XPG6) || defined(__EXTENSIONS__) 224 extern int ttyslot(void); 225 extern void *valloc(size_t); 226 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */ 227 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */ 228 229 #if defined(__EXTENSIONS__) || \ 230 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 231 defined(_XPG6) 232 extern int posix_memalign(void **, size_t, size_t); 233 extern int posix_openpt(int); 234 extern int setenv(const char *, const char *, int); 235 extern int unsetenv(const char *); 236 #endif 237 238 #if defined(__EXTENSIONS__) || \ 239 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 240 extern char *canonicalize_file_name(const char *); 241 extern int clearenv(void); 242 extern void closefrom(int); 243 extern int daemon(int, int); 244 extern int dup2(int, int); 245 extern int dup3(int, int, int); 246 extern int fdwalk(int (*)(void *, int), void *); 247 extern char *qecvt(long double, int, int *, int *); 248 extern char *qfcvt(long double, int, int *, int *); 249 extern char *qgcvt(long double, int, char *); 250 extern char *getcwd(char *, size_t); 251 extern const char *getexecname(void); 252 253 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in unistd.h */ 254 #define __GETLOGIN_DEFINED 255 #ifndef __USE_LEGACY_LOGNAME__ 256 #ifdef __PRAGMA_REDEFINE_EXTNAME 257 #pragma redefine_extname getlogin getloginx 258 #else /* __PRAGMA_REDEFINE_EXTNAME */ 259 extern char *getloginx(void); 260 #define getlogin getloginx 261 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 262 #endif /* __USE_LEGACY_LOGNAME__ */ 263 extern char *getlogin(void); 264 #endif /* __GETLOGIN_DEFINED */ 265 266 extern int getopt(int, char *const *, const char *); 267 extern char *optarg; 268 extern int optind, opterr, optopt; 269 extern char *getpass(const char *); 270 extern char *getpassphrase(const char *); 271 extern int getpw(uid_t, char *); 272 extern int isatty(int); 273 extern void *memalign(size_t, size_t); 274 extern char *ttyname(int); 275 extern char *mkdtemp(char *); 276 extern const char *getprogname(void); 277 extern void setprogname(const char *); 278 279 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) 280 extern char *lltostr(long long, char *); 281 extern char *ulltostr(unsigned long long, char *); 282 #endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */ 283 284 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 285 286 /* OpenBSD compatibility functions */ 287 #if !defined(_STRICT_SYMBOLS) 288 289 #include <inttypes.h> 290 extern uint32_t arc4random(void); 291 extern void arc4random_buf(void *, size_t); 292 extern uint32_t arc4random_uniform(uint32_t); 293 extern void *reallocarray(void *, size_t, size_t); 294 extern long long strtonum(const char *, long long, long long, const char **); 295 296 #endif /* !_STRICT_SYBMOLS */ 297 298 299 #ifdef __cplusplus 300 } 301 #endif 302 303 #endif /* _STDLIB_H */ 304