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 #else   /* __PRAGMA_REDEFINE_EXTNAME */
  98 #define mkstemp                 mkstemp64
  99 #define mkstemps                mkstemps64
 100 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 101 
 102 #endif  /* _FILE_OFFSET_BITS == 64 */
 103 
 104 /* In the LP64 compilation environment, all APIs are already large file */
 105 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
 106 
 107 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 108 #pragma redefine_extname        mkstemp64       mkstemp
 109 #pragma redefine_extname        mkstemps64      mkstemps
 110 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 111 #define mkstemp64               mkstemp
 112 #define mkstemps64              mkstemps
 113 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 114 
 115 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
 116 
 117 #if defined(__EXTENSIONS__) || \
 118         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
 119         (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
 120 extern int rand_r(unsigned int *);
 121 #endif
 122 
 123 extern void _exithandle(void);
 124 
 125 #if defined(__EXTENSIONS__) || \
 126         (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
 127         defined(_XPG4)
 128 extern double drand48(void);
 129 extern double erand48(unsigned short *);
 130 extern long jrand48(unsigned short *);
 131 extern void lcong48(unsigned short *);
 132 extern long lrand48(void);
 133 extern long mrand48(void);
 134 extern long nrand48(unsigned short *);
 135 extern unsigned short *seed48(unsigned short *);
 136 extern void srand48(long);
 137 extern int putenv(char *);
 138 extern void setkey(const char *);
 139 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
 140 
 141 /*
 142  * swab() has historically been in <stdlib.h> as delivered from AT&T
 143  * and continues to be visible in the default compilation environment.
 144  * As of Issue 4 of the X/Open Portability Guides, swab() was declared
 145  * in <unistd.h>. As a result, with respect to X/Open namespace the
 146  * swab() declaration in this header is only visible for the XPG3
 147  * environment.
 148  */
 149 #if (defined(__EXTENSIONS__) || \
 150         (!defined(_STRICT_STDC__) && !defined(_POSIX_C_SOURCE))) && \
 151         (!defined(_XOPEN_SOURCE) || (defined(_XPG3) && !defined(_XPG4)))
 152 #ifndef _SSIZE_T
 153 #define _SSIZE_T
 154 #if defined(_LP64) || defined(_I32LPx)
 155 typedef long    ssize_t;        /* size of something in bytes or -1 */
 156 #else
 157 typedef int     ssize_t;        /* (historical version) */
 158 #endif
 159 #endif  /* !_SSIZE_T */
 160 
 161 extern void swab(const char *, char *, ssize_t);
 162 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
 163 
 164 #if defined(__EXTENSIONS__) || \
 165         !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 166         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
 167 extern int      mkstemp(char *);
 168 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 169 extern int      mkstemps(char *, int);
 170 #endif
 171 #endif /* defined(__EXTENSIONS__) ... */
 172 
 173 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 174             !defined(__PRAGMA_REDEFINE_EXTNAME))
 175 extern int      mkstemp64(char *);
 176 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 177 extern int      mkstemps64(char *, int);
 178 #endif
 179 #endif  /* _LARGEFILE64_SOURCE... */
 180 
 181 /* Added in XPG4.2, obsoleted in Issue 6, removed in Issue 7 */
 182 #if !defined(_STRICT_SYMBOLS) || (defined(_XPG4_2) && !defined(_XPG7))
 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 #endif
 187 
 188 #if defined(__EXTENSIONS__) || \
 189         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
 190         defined(_XPG4_2)
 191 extern long a64l(const char *);
 192 extern int getsubopt(char **, char *const *, char **);
 193 extern int  grantpt(int);
 194 extern char *initstate(unsigned, char *, size_t);
 195 extern char *l64a(long);
 196 extern char *mktemp(char *);
 197 extern char *ptsname(int);
 198 extern long random(void);
 199 extern char *realpath(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
 200 extern char *setstate(const char *);
 201 extern void srandom(unsigned);
 202 extern int  unlockpt(int);
 203 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
 204 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 205 extern int ttyslot(void);
 206 extern void *valloc(size_t);
 207 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
 208 #endif /* defined(__EXTENSIONS__) || ... || defined(_XPG4_2) */
 209 
 210 #if defined(__EXTENSIONS__) || \
 211         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
 212         defined(_XPG6)
 213 extern int posix_memalign(void **, size_t, size_t);
 214 extern int posix_openpt(int);
 215 extern int setenv(const char *, const char *, int);
 216 extern int unsetenv(const char *);
 217 #endif
 218 
 219 #if defined(__EXTENSIONS__) || \
 220         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
 221 extern char *canonicalize_file_name(const char *);
 222 extern int clearenv(void);
 223 extern void closefrom(int);
 224 extern int daemon(int, int);
 225 extern int dup2(int, int);
 226 extern int dup3(int, int, int);
 227 extern int fdwalk(int (*)(void *, int), void *);
 228 extern char *qecvt(long double, int, int *, int *);
 229 extern char *qfcvt(long double, int, int *, int *);
 230 extern char *qgcvt(long double, int, char *);
 231 extern char *getcwd(char *, size_t);
 232 extern const char *getexecname(void);
 233 
 234 #ifndef __GETLOGIN_DEFINED      /* Avoid duplicate in unistd.h */
 235 #define __GETLOGIN_DEFINED
 236 #ifndef __USE_LEGACY_LOGNAME__
 237 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 238 #pragma redefine_extname getlogin getloginx
 239 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 240 extern char *getloginx(void);
 241 #define getlogin        getloginx
 242 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 243 #endif  /* __USE_LEGACY_LOGNAME__ */
 244 extern char *getlogin(void);
 245 #endif  /* __GETLOGIN_DEFINED */
 246 
 247 extern int getopt(int, char *const *, const char *);
 248 extern char *optarg;
 249 extern int optind, opterr, optopt;
 250 extern char *getpass(const char *);
 251 extern char *getpassphrase(const char *);
 252 extern int getpw(uid_t, char *);
 253 extern int isatty(int);
 254 extern void *memalign(size_t, size_t);
 255 extern char *ttyname(int);
 256 extern char *mkdtemp(char *);
 257 extern const char *getprogname(void);
 258 extern void setprogname(const char *);
 259 
 260 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
 261 extern char *lltostr(long long, char *);
 262 extern char *ulltostr(unsigned long long, char *);
 263 #endif  /* !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE) */
 264 
 265 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
 266 
 267 #ifdef  __cplusplus
 268 }
 269 #endif
 270 
 271 #endif  /* _STDLIB_H */