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 (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */ 27 28 /* Copyright (c) 1988 AT&T */ 29 /* All Rights Reserved */ 30 31 #ifndef _STDLIB_H 32 #define _STDLIB_H 33 34 #include <iso/stdlib_iso.h> 35 #include <iso/stdlib_c99.h> 36 37 #if defined(__EXTENSIONS__) || defined(_XPG4) 38 #include <sys/wait.h> 39 #endif 40 41 /* 42 * Allow global visibility for symbols defined in 43 * C++ "std" namespace in <iso/stdlib_iso.h>. 44 */ 45 #if __cplusplus >= 199711L 46 using std::div_t; 47 using std::ldiv_t; 48 using std::size_t; 49 using std::abort; 50 using std::abs; 51 using std::atexit; 52 using std::atof; 53 using std::atoi; 54 using std::atol; 55 using std::bsearch; 56 using std::calloc; 57 using std::div; 58 using std::exit; 59 using std::free; 60 using std::getenv; 61 using std::labs; 62 using std::ldiv; 63 using std::malloc; 64 using std::mblen; 65 using std::mbstowcs; 66 using std::mbtowc; 67 using std::qsort; 68 using std::rand; 69 using std::realloc; 70 using std::srand; 71 using std::strtod; 72 using std::strtol; 73 using std::strtoul; 74 using std::system; 75 using std::wcstombs; 76 using std::wctomb; 77 #endif 78 79 #ifdef __cplusplus 80 extern "C" { 81 #endif 82 83 #ifndef _UID_T 84 #define _UID_T 85 typedef unsigned int uid_t; /* UID type */ 86 #endif /* !_UID_T */ 87 88 #if defined(__STDC__) 89 90 /* large file compilation environment setup */ 91 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 92 93 #ifdef __PRAGMA_REDEFINE_EXTNAME 94 #pragma redefine_extname mkstemp mkstemp64 95 #pragma redefine_extname mkstemps mkstemps64 96 #else /* __PRAGMA_REDEFINE_EXTNAME */ 97 #define mkstemp mkstemp64 98 #define mkstemps mkstemps64 99 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 100 101 #endif /* _FILE_OFFSET_BITS == 64 */ 102 103 /* In the LP64 compilation environment, all APIs are already large file */ 104 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 105 106 #ifdef __PRAGMA_REDEFINE_EXTNAME 107 #pragma redefine_extname mkstemp64 mkstemp 108 #pragma redefine_extname mkstemps64 mkstemps 109 #else /* __PRAGMA_REDEFINE_EXTNAME */ 110 #define mkstemp64 mkstemp 111 #define mkstemps64 mkstemps 112 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 113 114 #endif /* _LP64 && _LARGEFILE64_SOURCE */ 115 116 #if defined(__EXTENSIONS__) || \ 117 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 118 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT) 119 extern int rand_r(unsigned int *); 120 #endif 121 122 extern void _exithandle(void); 123 124 #if defined(__EXTENSIONS__) || \ 125 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 126 defined(_XPG4) 127 extern double drand48(void); 128 extern double erand48(unsigned short *); 129 extern long jrand48(unsigned short *); 130 extern void lcong48(unsigned short *); 131 extern long lrand48(void); 132 extern long mrand48(void); 133 extern long nrand48(unsigned short *); 134 extern unsigned short *seed48(unsigned short *); 135 extern void srand48(long); 136 extern int putenv(char *); 137 extern void setkey(const char *); 138 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 139 140 /* 141 * swab() has historically been in <stdlib.h> as delivered from AT&T 142 * and continues to be visible in the default compilation environment. 143 * As of Issue 4 of the X/Open Portability Guides, swab() was declared 144 * in <unistd.h>. As a result, with respect to X/Open namespace the 145 * swab() declaration in this header is only visible for the XPG3 146 * environment. 147 */ 148 #if (defined(__EXTENSIONS__) || \ 149 (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \ 150 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4))) 151 #ifndef _SSIZE_T 152 #define _SSIZE_T 153 #if defined(_LP64) || defined(_I32LPx) 154 typedef long ssize_t; /* size of something in bytes or -1 */ 155 #else 156 typedef int ssize_t; /* (historical version) */ 157 #endif 158 #endif /* !_SSIZE_T */ 159 160 extern void swab(const char *, char *, ssize_t); 161 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 162 163 #if defined(__EXTENSIONS__) || \ 164 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 165 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) 166 extern int mkstemp(char *); 167 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 168 extern int mkstemps(char *, int); 169 #endif 170 #endif /* defined(__EXTENSIONS__) ... */ 171 172 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 173 !defined(__PRAGMA_REDEFINE_EXTNAME)) 174 extern int mkstemp64(char *); 175 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 176 extern int mkstemps64(char *, int); 177 #endif 178 #endif /* _LARGEFILE64_SOURCE... */ 179 180 #if defined(__EXTENSIONS__) || \ 181 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 182 defined(_XPG4_2) 183 extern long a64l(const char *); 184 extern char *ecvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD); 185 extern char *fcvt(double, int, int *_RESTRICT_KYWD, int *_RESTRICT_KYWD); 186 extern char *gcvt(double, int, char *); 187 extern int getsubopt(char **, char *const *, char **); 188 extern int grantpt(int); 189 extern char *initstate(unsigned, char *, size_t); 190 extern char *l64a(long); 191 extern char *mktemp(char *); 192 extern char *ptsname(int); 193 extern long random(void); 194 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD); 195 extern char *setstate(const char *); 196 extern void srandom(unsigned); 197 extern int unlockpt(int); 198 /* Marked LEGACY in SUSv2 and removed in SUSv3 */ 199 #if !defined(_XPG6) || defined(__EXTENSIONS__) 200 extern int ttyslot(void); 201 extern void *valloc(size_t); 202 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */ 203 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */ 204 205 #if defined(__EXTENSIONS__) || \ 206 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 207 defined(_XPG6) 208 extern int posix_memalign(void **, size_t, size_t); 209 extern int posix_openpt(int); 210 extern int setenv(const char *, const char *, int); 211 extern int unsetenv(const char *); 212 #endif 213 214 #if defined(__EXTENSIONS__) || \ 215 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 216 extern char *canonicalize_file_name(const char *); 217 extern int clearenv(void); 218 extern void closefrom(int); 219 extern int daemon(int, int); 220 extern int dup2(int, int); 221 extern int dup3(int, int, int); 222 extern int fdwalk(int (*)(void *, int), void *); 223 extern char *qecvt(long double, int, int *, int *); 224 extern char *qfcvt(long double, int, int *, int *); 225 extern char *qgcvt(long double, int, char *); 226 extern char *getcwd(char *, size_t); 227 extern const char *getexecname(void); 228 extern char *getlogin(void); 229 extern int getopt(int, char *const *, const char *); 230 extern char *optarg; 231 extern int optind, opterr, optopt; 232 extern char *getpass(const char *); 233 extern char *getpassphrase(const char *); 234 extern int getpw(uid_t, char *); 235 extern int isatty(int); 236 extern void *memalign(size_t, size_t); 237 extern char *ttyname(int); 238 extern char *mkdtemp(char *); 239 extern const char *getprogname(void); 240 extern void setprogname(const char *); 241 242 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) 243 extern char *lltostr(long long, char *); 244 extern char *ulltostr(unsigned long long, char *); 245 #endif /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */ 246 247 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */ 248 249 #else /* not __STDC__ */ 250 251 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \ 252 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT) 253 extern int rand_r(); 254 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT) ... */ 255 256 extern void _exithandle(); 257 258 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || defined(_XPG4) 259 extern double drand48(); 260 extern double erand48(); 261 extern long jrand48(); 262 extern void lcong48(); 263 extern long lrand48(); 264 extern long mrand48(); 265 extern long nrand48(); 266 extern unsigned short *seed48(); 267 extern void srand48(); 268 extern int putenv(); 269 extern void setkey(); 270 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */ 271 272 #if (defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)) && \ 273 (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4))) 274 extern void swab(); 275 #endif 276 277 #if defined(__EXTENSIONS__) || \ 278 !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 279 (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) 280 extern int mkstemp(); 281 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 282 extern int mkstemps(); 283 #endif 284 #endif /* defined(__EXTENSIONS__) ... */ 285 286 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 287 !defined(__PRAGMA_REDEFINE_EXTNAME)) 288 extern int mkstemp64(); 289 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 290 extern int mkstemps64(); 291 #endif 292 #endif /* _LARGEFILE64_SOURCE... */ 293 294 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) 295 extern long a64l(); 296 extern char *ecvt(); 297 extern char *fcvt(); 298 extern char *gcvt(); 299 extern int getsubopt(); 300 extern int grantpt(); 301 extern char *initstate(); 302 extern char *l64a(); 303 extern char *mktemp(); 304 extern char *ptsname(); 305 extern long random(); 306 extern char *realpath(); 307 extern char *setstate(); 308 extern void srandom(); 309 /* Marked LEGACY in SUSv2 and removed in SUSv3 */ 310 #if !defined(_XPG6) || defined(__EXTENSIONS__) 311 extern int ttyslot(); 312 extern void *valloc(); 313 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */ 314 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */ 315 316 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6) 317 extern int posix_memalign(); 318 extern int posix_openpt(); 319 extern int setenv(); 320 extern int unsetenv(); 321 #endif 322 323 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) 324 extern char *canonicalize_file_name(); 325 extern int clearenv(); 326 extern void closefrom(); 327 extern int daemon(); 328 extern int dup2(); 329 extern int dup3(); 330 extern int fdwalk(); 331 extern char *qecvt(); 332 extern char *qfcvt(); 333 extern char *qgcvt(); 334 extern char *getcwd(); 335 extern char *getexecname(); 336 extern char *getlogin(); 337 extern int getopt(); 338 extern char *optarg; 339 extern int optind, opterr, optopt; 340 extern char *getpass(); 341 extern char *getpassphrase(); 342 extern int getpw(); 343 extern int isatty(); 344 extern void *memalign(); 345 extern char *ttyname(); 346 extern char *mkdtemp(); 347 extern char *getprogname(); 348 extern void setprogname(); 349 350 #if defined(_LONGLONG_TYPE) 351 extern char *lltostr(); 352 extern char *ulltostr(); 353 #endif /* defined(_LONGLONG_TYPE) */ 354 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */ 355 356 #endif /* __STDC__ */ 357 358 #ifdef __cplusplus 359 } 360 #endif 361 362 #endif /* _STDLIB_H */ 363