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