1 /* A GNU-like <stdlib.h>.
3 Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc.
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.
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.
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/>. */
19 @PRAGMA_SYSTEM_HEADER@
22 #if defined __need_malloc_and_calloc
23 /* Special invocation convention inside glibc header files. */
25 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
28 /* Normal invocation convention. */
32 /* The include_next requires a split double-inclusion guard. */
33 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
38 /* NetBSD 5.0 mis-defines NULL. */
41 /* Solaris declares getloadavg() in <sys/loadavg.h>. */
42 #if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
43 # include <sys/loadavg.h>
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. */
52 #if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@
56 #if !@HAVE_STRUCT_RANDOM_DATA@
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. */
69 /* The definition of GL_LINK_WARNING is copied here. */
71 /* The definition of _GL_ARG_NONNULL is copied here. */
74 /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
76 # define EXIT_SUCCESS 0
78 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
79 with proper operation of xargs. */
81 # define EXIT_FAILURE 1
82 #elif EXIT_FAILURE != 1
84 # define EXIT_FAILURE 1
94 /* Parse a signed decimal integer.
95 Returns the value of the integer. Errors are not detected. */
96 extern long long atoll (const char *string) _GL_ARG_NONNULL ((1));
98 #elif defined GNULIB_POSIXCHECK
101 (GL_LINK_WARNING ("atoll is unportable - " \
102 "use gnulib module atoll for portability"), \
106 #if @GNULIB_CALLOC_POSIX@
107 # if !@HAVE_CALLOC_POSIX@
109 # define calloc rpl_calloc
110 extern void * calloc (size_t nmemb, size_t size);
112 #elif defined GNULIB_POSIXCHECK
114 # define calloc(n,s) \
115 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
116 "use gnulib module calloc-posix for portability"), \
120 #if @GNULIB_CANONICALIZE_FILE_NAME@
121 # if @REPLACE_CANONICALIZE_FILE_NAME@
122 # define canonicalize_file_name rpl_canonicalize_file_name
124 # if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@
125 extern char *canonicalize_file_name (const char *name) _GL_ARG_NONNULL ((1));
127 #elif defined GNULIB_POSIXCHECK
128 # undef canonicalize_file_name
129 # define canonicalize_file_name(n) \
130 (GL_LINK_WARNING ("canonicalize_file_name is unportable - " \
131 "use gnulib module canonicalize-lgpl for portability"), \
132 canonicalize_file_name (n))
135 #if @GNULIB_GETLOADAVG@
136 # if !@HAVE_DECL_GETLOADAVG@
137 /* Store max(NELEM,3) load average numbers in LOADAVG[].
138 The three numbers are the load average of the last 1 minute, the last 5
139 minutes, and the last 15 minutes, respectively.
140 LOADAVG is an array of NELEM numbers. */
141 extern int getloadavg (double loadavg[], int nelem) _GL_ARG_NONNULL ((1));
143 #elif defined GNULIB_POSIXCHECK
145 # define getloadavg(l,n) \
146 (GL_LINK_WARNING ("getloadavg is not portable - " \
147 "use gnulib module getloadavg for portability"), \
151 #if @GNULIB_GETSUBOPT@
152 /* Assuming *OPTIONP is a comma separated list of elements of the form
153 "token" or "token=value", getsubopt parses the first of these elements.
154 If the first element refers to a "token" that is member of the given
155 NULL-terminated array of tokens:
156 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
157 the first option and the comma, sets *VALUEP to the value of the
158 element (or NULL if it doesn't contain an "=" sign),
159 - It returns the index of the "token" in the given array of tokens.
160 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
161 For more details see the POSIX:2001 specification.
162 http://www.opengroup.org/susv3xsh/getsubopt.html */
163 # if !@HAVE_GETSUBOPT@
164 extern int getsubopt (char **optionp, char *const *tokens, char **valuep)
165 _GL_ARG_NONNULL ((1, 2, 3));
167 #elif defined GNULIB_POSIXCHECK
169 # define getsubopt(o,t,v) \
170 (GL_LINK_WARNING ("getsubopt is unportable - " \
171 "use gnulib module getsubopt for portability"), \
175 #if @GNULIB_MALLOC_POSIX@
176 # if !@HAVE_MALLOC_POSIX@
178 # define malloc rpl_malloc
179 extern void * malloc (size_t size);
181 #elif defined GNULIB_POSIXCHECK
184 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
185 "use gnulib module malloc-posix for portability"), \
191 /* Create a unique temporary directory from TEMPLATE.
192 The last six characters of TEMPLATE must be "XXXXXX";
193 they are replaced with a string that makes the directory name unique.
194 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
195 The directory is created mode 700. */
196 extern char * mkdtemp (char * /*template*/) _GL_ARG_NONNULL ((1));
198 #elif defined GNULIB_POSIXCHECK
200 # define mkdtemp(t) \
201 (GL_LINK_WARNING ("mkdtemp is unportable - " \
202 "use gnulib module mkdtemp for portability"), \
206 #if @GNULIB_MKOSTEMP@
207 # if !@HAVE_MKOSTEMP@
208 /* Create a unique temporary file from TEMPLATE.
209 The last six characters of TEMPLATE must be "XXXXXX";
210 they are replaced with a string that makes the file name unique.
211 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
212 and O_TEXT, O_BINARY (defined in "binary-io.h").
213 The file is then created, with the specified flags, ensuring it didn't exist
215 The file is created read-write (mask at least 0600 & ~umask), but it may be
216 world-readable and world-writable (mask 0666 & ~umask), depending on the
218 Returns the open file descriptor if successful, otherwise -1 and errno
220 extern int mkostemp (char * /*template*/, int /*flags*/) _GL_ARG_NONNULL ((1));
222 #elif defined GNULIB_POSIXCHECK
224 # define mkostemp(t,f) \
225 (GL_LINK_WARNING ("mkostemp is unportable - " \
226 "use gnulib module mkostemp for portability"), \
230 #if @GNULIB_MKOSTEMPS@
231 # if !@HAVE_MKOSTEMPS@
232 /* Create a unique temporary file from TEMPLATE.
233 The last six characters of TEMPLATE before a suffix of length
234 SUFFIXLEN must be "XXXXXX";
235 they are replaced with a string that makes the file name unique.
236 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
237 and O_TEXT, O_BINARY (defined in "binary-io.h").
238 The file is then created, with the specified flags, ensuring it didn't exist
240 The file is created read-write (mask at least 0600 & ~umask), but it may be
241 world-readable and world-writable (mask 0666 & ~umask), depending on the
243 Returns the open file descriptor if successful, otherwise -1 and errno
245 extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/)
246 _GL_ARG_NONNULL ((1));
248 #elif defined GNULIB_POSIXCHECK
250 # define mkostemps(t,s,f) \
251 (GL_LINK_WARNING ("mkostemps is unportable - " \
252 "use gnulib module mkostemps for portability"), \
257 # if @REPLACE_MKSTEMP@
258 /* Create a unique temporary file from TEMPLATE.
259 The last six characters of TEMPLATE must be "XXXXXX";
260 they are replaced with a string that makes the file name unique.
261 The file is then created, ensuring it didn't exist before.
262 The file is created read-write (mask at least 0600 & ~umask), but it may be
263 world-readable and world-writable (mask 0666 & ~umask), depending on the
265 Returns the open file descriptor if successful, otherwise -1 and errno
267 # define mkstemp rpl_mkstemp
268 extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1));
270 /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
273 #elif defined GNULIB_POSIXCHECK
275 # define mkstemp(t) \
276 (GL_LINK_WARNING ("mkstemp is unportable - " \
277 "use gnulib module mkstemp for portability"), \
281 #if @GNULIB_MKSTEMPS@
282 # if !@HAVE_MKSTEMPS@
283 /* Create a unique temporary file from TEMPLATE.
284 The last six characters of TEMPLATE prior to a suffix of length
285 SUFFIXLEN must be "XXXXXX";
286 they are replaced with a string that makes the file name unique.
287 The file is then created, ensuring it didn't exist before.
288 The file is created read-write (mask at least 0600 & ~umask), but it may be
289 world-readable and world-writable (mask 0666 & ~umask), depending on the
291 Returns the open file descriptor if successful, otherwise -1 and errno
293 extern int mkstemps (char * /*template*/, int /*suffixlen*/)
294 _GL_ARG_NONNULL ((1));
296 #elif defined GNULIB_POSIXCHECK
298 # define mkstemps(t,s) \
299 (GL_LINK_WARNING ("mkstemps is unportable - " \
300 "use gnulib module mkstemps for portability"), \
305 # if @REPLACE_PUTENV@
307 # define putenv rpl_putenv
308 extern int putenv (char *string) _GL_ARG_NONNULL ((1));
312 #if @GNULIB_RANDOM_R@
313 # if !@HAVE_RANDOM_R@
316 # define RAND_MAX 2147483647
319 int srandom_r (unsigned int seed, struct random_data *rand_state)
320 _GL_ARG_NONNULL ((2));
321 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
322 struct random_data *rand_state)
323 _GL_ARG_NONNULL ((2, 4));
324 int setstate_r (char *arg_state, struct random_data *rand_state)
325 _GL_ARG_NONNULL ((1, 2));
326 int random_r (struct random_data *buf, int32_t *result)
327 _GL_ARG_NONNULL ((1, 2));
329 #elif defined GNULIB_POSIXCHECK
331 # define random_r(b,r) \
332 (GL_LINK_WARNING ("random_r is unportable - " \
333 "use gnulib module random_r for portability"), \
336 # define initstate_r(s,b,sz,r) \
337 (GL_LINK_WARNING ("initstate_r is unportable - " \
338 "use gnulib module random_r for portability"), \
339 initstate_r (s,b,sz,r))
341 # define srandom_r(s,r) \
342 (GL_LINK_WARNING ("srandom_r is unportable - " \
343 "use gnulib module random_r for portability"), \
346 # define setstate_r(a,r) \
347 (GL_LINK_WARNING ("setstate_r is unportable - " \
348 "use gnulib module random_r for portability"), \
352 #if @GNULIB_REALLOC_POSIX@
353 # if !@HAVE_REALLOC_POSIX@
355 # define realloc rpl_realloc
356 extern void * realloc (void *ptr, size_t size);
358 #elif defined GNULIB_POSIXCHECK
360 # define realloc(p,s) \
361 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
362 "use gnulib module realloc-posix for portability"), \
366 #if @GNULIB_REALPATH@
367 # if @REPLACE_REALPATH@
368 # define realpath rpl_realpath
370 # if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
371 extern char *realpath (const char *name, char *resolved) _GL_ARG_NONNULL ((1));
373 #elif defined GNULIB_POSIXCHECK
375 # define realpath(n,r) \
376 (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \
377 "canonicalize or canonicalize-lgpl for portability"), \
383 /* Test a user response to a question.
384 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
385 extern int rpmatch (const char *response) _GL_ARG_NONNULL ((1));
387 #elif defined GNULIB_POSIXCHECK
389 # define rpmatch(r) \
390 (GL_LINK_WARNING ("rpmatch is unportable - " \
391 "use gnulib module rpmatch for portability"), \
396 # if @REPLACE_SETENV@
398 # define setenv rpl_setenv
400 # if !@HAVE_SETENV@ || @REPLACE_SETENV@
401 /* Set NAME to VALUE in the environment.
402 If REPLACE is nonzero, overwrite an existing value. */
403 extern int setenv (const char *name, const char *value, int replace)
404 _GL_ARG_NONNULL ((1));
406 #elif defined GNULIB_POSIXCHECK
408 # define setenv(n,v,o) \
409 (GL_LINK_WARNING ("setenv is unportable - " \
410 "use gnulib module setenv for portability"), \
415 # if @REPLACE_STRTOD@
416 # define strtod rpl_strtod
418 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
419 /* Parse a double from STRING, updating ENDP if appropriate. */
420 extern double strtod (const char *str, char **endp) _GL_ARG_NONNULL ((1));
422 #elif defined GNULIB_POSIXCHECK
424 # define strtod(s, e) \
425 (GL_LINK_WARNING ("strtod is unportable - " \
426 "use gnulib module strtod for portability"), \
432 /* Parse a signed integer whose textual representation starts at STRING.
433 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
434 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
436 If ENDPTR is not NULL, the address of the first byte after the integer is
438 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
440 extern long long strtoll (const char *string, char **endptr, int base)
441 _GL_ARG_NONNULL ((1));
443 #elif defined GNULIB_POSIXCHECK
445 # define strtoll(s,e,b) \
446 (GL_LINK_WARNING ("strtoll is unportable - " \
447 "use gnulib module strtoll for portability"), \
451 #if @GNULIB_STRTOULL@
452 # if !@HAVE_STRTOULL@
453 /* Parse an unsigned integer whose textual representation starts at STRING.
454 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
455 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
457 If ENDPTR is not NULL, the address of the first byte after the integer is
459 Upon overflow, the return value is ULLONG_MAX, and errno is set to
461 extern unsigned long long strtoull (const char *string, char **endptr, int base)
462 _GL_ARG_NONNULL ((1));
464 #elif defined GNULIB_POSIXCHECK
466 # define strtoull(s,e,b) \
467 (GL_LINK_WARNING ("strtoull is unportable - " \
468 "use gnulib module strtoull for portability"), \
472 #if @GNULIB_UNSETENV@
473 # if @REPLACE_UNSETENV@
475 # define unsetenv rpl_unsetenv
477 # if !@HAVE_UNSETENV@ || @REPLACE_UNSETENV@
478 /* Remove the variable NAME from the environment. */
479 extern int unsetenv (const char *name) _GL_ARG_NONNULL ((1));
481 #elif defined GNULIB_POSIXCHECK
483 # define unsetenv(n) \
484 (GL_LINK_WARNING ("unsetenv is unportable - " \
485 "use gnulib module unsetenv for portability"), \
493 #endif /* _GL_STDLIB_H */
494 #endif /* _GL_STDLIB_H */