1/* A GNU-like <stdlib.h>. 2 3 Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc. 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18#if __GNUC__ >= 3 19@PRAGMA_SYSTEM_HEADER@ 20#endif 21 22#if defined __need_malloc_and_calloc 23/* Special invocation convention inside glibc header files. */ 24 25#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ 26 27#else 28/* Normal invocation convention. */ 29 30#ifndef _GL_STDLIB_H 31 32/* The include_next requires a split double-inclusion guard. */ 33#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ 34 35#ifndef _GL_STDLIB_H 36#define _GL_STDLIB_H 37 38/* NetBSD 5.0 mis-defines NULL. */ 39#include <stddef.h> 40 41/* Solaris declares getloadavg() in <sys/loadavg.h>. */ 42#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@ 43# include <sys/loadavg.h> 44#endif 45 46/* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included 47 from <stdlib.h> if _REENTRANT is defined. Include it always. */ 48#if @HAVE_RANDOM_H@ 49# include <random.h> 50#endif 51 52#if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@ 53# include <stdint.h> 54#endif 55 56#if !@HAVE_STRUCT_RANDOM_DATA@ 57struct random_data 58{ 59 int32_t *fptr; /* Front pointer. */ 60 int32_t *rptr; /* Rear pointer. */ 61 int32_t *state; /* Array of state values. */ 62 int rand_type; /* Type of random number generator. */ 63 int rand_deg; /* Degree of random number generator. */ 64 int rand_sep; /* Distance between front and rear. */ 65 int32_t *end_ptr; /* Pointer behind state table. */ 66}; 67#endif 68 69/* The definition of GL_LINK_WARNING is copied here. */ 70 71 72/* Some systems do not define EXIT_*, despite otherwise supporting C89. */ 73#ifndef EXIT_SUCCESS 74# define EXIT_SUCCESS 0 75#endif 76/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere 77 with proper operation of xargs. */ 78#ifndef EXIT_FAILURE 79# define EXIT_FAILURE 1 80#elif EXIT_FAILURE != 1 81# undef EXIT_FAILURE 82# define EXIT_FAILURE 1 83#endif 84 85 86#ifdef __cplusplus 87extern "C" { 88#endif 89 90 91#if @GNULIB_MALLOC_POSIX@ 92# if !@HAVE_MALLOC_POSIX@ 93# undef malloc 94# define malloc rpl_malloc 95extern void * malloc (size_t size); 96# endif 97#elif defined GNULIB_POSIXCHECK 98# undef malloc 99# define malloc(s) \ 100 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \ 101 "use gnulib module malloc-posix for portability"), \ 102 malloc (s)) 103#endif 104 105 106#if @GNULIB_REALLOC_POSIX@ 107# if !@HAVE_REALLOC_POSIX@ 108# undef realloc 109# define realloc rpl_realloc 110extern void * realloc (void *ptr, size_t size); 111# endif 112#elif defined GNULIB_POSIXCHECK 113# undef realloc 114# define realloc(p,s) \ 115 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \ 116 "use gnulib module realloc-posix for portability"), \ 117 realloc (p, s)) 118#endif 119 120 121#if @GNULIB_CALLOC_POSIX@ 122# if !@HAVE_CALLOC_POSIX@ 123# undef calloc 124# define calloc rpl_calloc 125extern void * calloc (size_t nmemb, size_t size); 126# endif 127#elif defined GNULIB_POSIXCHECK 128# undef calloc 129# define calloc(n,s) \ 130 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \ 131 "use gnulib module calloc-posix for portability"), \ 132 calloc (n, s)) 133#endif 134 135 136#if @GNULIB_ATOLL@ 137# if !@HAVE_ATOLL@ 138/* Parse a signed decimal integer. 139 Returns the value of the integer. Errors are not detected. */ 140extern long long atoll (const char *string); 141# endif 142#elif defined GNULIB_POSIXCHECK 143# undef atoll 144# define atoll(s) \ 145 (GL_LINK_WARNING ("atoll is unportable - " \ 146 "use gnulib module atoll for portability"), \ 147 atoll (s)) 148#endif 149 150 151#if @GNULIB_GETLOADAVG@ 152# if !@HAVE_DECL_GETLOADAVG@ 153/* Store max(NELEM,3) load average numbers in LOADAVG[]. 154 The three numbers are the load average of the last 1 minute, the last 5 155 minutes, and the last 15 minutes, respectively. 156 LOADAVG is an array of NELEM numbers. */ 157extern int getloadavg (double loadavg[], int nelem); 158# endif 159#elif defined GNULIB_POSIXCHECK 160# undef getloadavg 161# define getloadavg(l,n) \ 162 (GL_LINK_WARNING ("getloadavg is not portable - " \ 163 "use gnulib module getloadavg for portability"), \ 164 getloadavg (l, n)) 165#endif 166 167 168#if @GNULIB_GETSUBOPT@ 169/* Assuming *OPTIONP is a comma separated list of elements of the form 170 "token" or "token=value", getsubopt parses the first of these elements. 171 If the first element refers to a "token" that is member of the given 172 NULL-terminated array of tokens: 173 - It replaces the comma with a NUL byte, updates *OPTIONP to point past 174 the first option and the comma, sets *VALUEP to the value of the 175 element (or NULL if it doesn't contain an "=" sign), 176 - It returns the index of the "token" in the given array of tokens. 177 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. 178 For more details see the POSIX:2001 specification. 179 http://www.opengroup.org/susv3xsh/getsubopt.html */ 180# if !@HAVE_GETSUBOPT@ 181extern int getsubopt (char **optionp, char *const *tokens, char **valuep); 182# endif 183#elif defined GNULIB_POSIXCHECK 184# undef getsubopt 185# define getsubopt(o,t,v) \ 186 (GL_LINK_WARNING ("getsubopt is unportable - " \ 187 "use gnulib module getsubopt for portability"), \ 188 getsubopt (o, t, v)) 189#endif 190 191 192#if @GNULIB_MKDTEMP@ 193# if !@HAVE_MKDTEMP@ 194/* Create a unique temporary directory from TEMPLATE. 195 The last six characters of TEMPLATE must be "XXXXXX"; 196 they are replaced with a string that makes the directory name unique. 197 Returns TEMPLATE, or a null pointer if it cannot get a unique name. 198 The directory is created mode 700. */ 199extern char * mkdtemp (char * /*template*/); 200# endif 201#elif defined GNULIB_POSIXCHECK 202# undef mkdtemp 203# define mkdtemp(t) \ 204 (GL_LINK_WARNING ("mkdtemp is unportable - " \ 205 "use gnulib module mkdtemp for portability"), \ 206 mkdtemp (t)) 207#endif 208 209 210#if @GNULIB_MKOSTEMP@ 211# if !@HAVE_MKOSTEMP@ 212/* Create a unique temporary file from TEMPLATE. 213 The last six characters of TEMPLATE must be "XXXXXX"; 214 they are replaced with a string that makes the file name unique. 215 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) 216 and O_TEXT, O_BINARY (defined in "binary-io.h"). 217 The file is then created, with the specified flags, ensuring it didn't exist 218 before. 219 The file is created read-write (mask at least 0600 & ~umask), but it may be 220 world-readable and world-writable (mask 0666 & ~umask), depending on the 221 implementation. 222 Returns the open file descriptor if successful, otherwise -1 and errno 223 set. */ 224extern int mkostemp (char * /*template*/, int /*flags*/); 225# endif 226#elif defined GNULIB_POSIXCHECK 227# undef mkostemp 228# define mkostemp(t,f) \ 229 (GL_LINK_WARNING ("mkostemp is unportable - " \ 230 "use gnulib module mkostemp for portability"), \ 231 mkostemp (t, f)) 232#endif 233 234 235#if @GNULIB_MKSTEMP@ 236# if @REPLACE_MKSTEMP@ 237/* Create a unique temporary file from TEMPLATE. 238 The last six characters of TEMPLATE must be "XXXXXX"; 239 they are replaced with a string that makes the file name unique. 240 The file is then created, ensuring it didn't exist before. 241 The file is created read-write (mask at least 0600 & ~umask), but it may be 242 world-readable and world-writable (mask 0666 & ~umask), depending on the 243 implementation. 244 Returns the open file descriptor if successful, otherwise -1 and errno 245 set. */ 246# define mkstemp rpl_mkstemp 247extern int mkstemp (char * /*template*/); 248# else 249/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ 250# include <unistd.h> 251# endif 252#elif defined GNULIB_POSIXCHECK 253# undef mkstemp 254# define mkstemp(t) \ 255 (GL_LINK_WARNING ("mkstemp is unportable - " \ 256 "use gnulib module mkstemp for portability"), \ 257 mkstemp (t)) 258#endif 259 260 261#if @GNULIB_PUTENV@ 262# if @REPLACE_PUTENV@ 263# undef putenv 264# define putenv rpl_putenv 265extern int putenv (char *string); 266# endif 267#endif 268 269 270#if @GNULIB_RANDOM_R@ 271# if !@HAVE_RANDOM_R@ 272 273# ifndef RAND_MAX 274# define RAND_MAX 2147483647 275# endif 276 277int srandom_r (unsigned int seed, struct random_data *rand_state); 278int initstate_r (unsigned int seed, char *buf, size_t buf_size, 279 struct random_data *rand_state); 280int setstate_r (char *arg_state, struct random_data *rand_state); 281int random_r (struct random_data *buf, int32_t *result); 282# endif 283#elif defined GNULIB_POSIXCHECK 284# undef random_r 285# define random_r(b,r) \ 286 (GL_LINK_WARNING ("random_r is unportable - " \ 287 "use gnulib module random_r for portability"), \ 288 random_r (b,r)) 289# undef initstate_r 290# define initstate_r(s,b,sz,r) \ 291 (GL_LINK_WARNING ("initstate_r is unportable - " \ 292 "use gnulib module random_r for portability"), \ 293 initstate_r (s,b,sz,r)) 294# undef srandom_r 295# define srandom_r(s,r) \ 296 (GL_LINK_WARNING ("srandom_r is unportable - " \ 297 "use gnulib module random_r for portability"), \ 298 srandom_r (s,r)) 299# undef setstate_r 300# define setstate_r(a,r) \ 301 (GL_LINK_WARNING ("setstate_r is unportable - " \ 302 "use gnulib module random_r for portability"), \ 303 setstate_r (a,r)) 304#endif 305 306 307#if @GNULIB_RPMATCH@ 308# if !@HAVE_RPMATCH@ 309/* Test a user response to a question. 310 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ 311extern int rpmatch (const char *response); 312# endif 313#elif defined GNULIB_POSIXCHECK 314# undef rpmatch 315# define rpmatch(r) \ 316 (GL_LINK_WARNING ("rpmatch is unportable - " \ 317 "use gnulib module rpmatch for portability"), \ 318 rpmatch (r)) 319#endif 320 321 322#if @GNULIB_SETENV@ 323# if !@HAVE_SETENV@ 324/* Set NAME to VALUE in the environment. 325 If REPLACE is nonzero, overwrite an existing value. */ 326extern int setenv (const char *name, const char *value, int replace); 327# endif 328#endif 329 330 331#if @GNULIB_UNSETENV@ 332# if @HAVE_UNSETENV@ 333# if @VOID_UNSETENV@ 334/* On some systems, unsetenv() returns void. 335 This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ 336# define unsetenv(name) ((unsetenv)(name), 0) 337# endif 338# else 339/* Remove the variable NAME from the environment. */ 340extern int unsetenv (const char *name); 341# endif 342#endif 343 344 345#if @GNULIB_STRTOD@ 346# if @REPLACE_STRTOD@ 347# define strtod rpl_strtod 348# endif 349# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@ 350 /* Parse a double from STRING, updating ENDP if appropriate. */ 351extern double strtod (const char *str, char **endp); 352# endif 353#elif defined GNULIB_POSIXCHECK 354# undef strtod 355# define strtod(s, e) \ 356 (GL_LINK_WARNING ("strtod is unportable - " \ 357 "use gnulib module strtod for portability"), \ 358 strtod (s, e)) 359#endif 360 361 362#if @GNULIB_STRTOLL@ 363# if !@HAVE_STRTOLL@ 364/* Parse a signed integer whose textual representation starts at STRING. 365 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 366 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix 367 "0x"). 368 If ENDPTR is not NULL, the address of the first byte after the integer is 369 stored in *ENDPTR. 370 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set 371 to ERANGE. */ 372extern long long strtoll (const char *string, char **endptr, int base); 373# endif 374#elif defined GNULIB_POSIXCHECK 375# undef strtoll 376# define strtoll(s,e,b) \ 377 (GL_LINK_WARNING ("strtoll is unportable - " \ 378 "use gnulib module strtoll for portability"), \ 379 strtoll (s, e, b)) 380#endif 381 382 383#if @GNULIB_STRTOULL@ 384# if !@HAVE_STRTOULL@ 385/* Parse an unsigned integer whose textual representation starts at STRING. 386 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 387 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix 388 "0x"). 389 If ENDPTR is not NULL, the address of the first byte after the integer is 390 stored in *ENDPTR. 391 Upon overflow, the return value is ULLONG_MAX, and errno is set to 392 ERANGE. */ 393extern unsigned long long strtoull (const char *string, char **endptr, int base); 394# endif 395#elif defined GNULIB_POSIXCHECK 396# undef strtoull 397# define strtoull(s,e,b) \ 398 (GL_LINK_WARNING ("strtoull is unportable - " \ 399 "use gnulib module strtoull for portability"), \ 400 strtoull (s, e, b)) 401#endif 402 403 404#ifdef __cplusplus 405} 406#endif 407 408#endif /* _GL_STDLIB_H */ 409#endif /* _GL_STDLIB_H */ 410#endif 411