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