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. */
72 /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
74 # define EXIT_SUCCESS 0
76 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
77 with proper operation of xargs. */
79 # define EXIT_FAILURE 1
80 #elif EXIT_FAILURE != 1
82 # define EXIT_FAILURE 1
92 /* Parse a signed decimal integer.
93 Returns the value of the integer. Errors are not detected. */
94 extern long long atoll (const char *string);
96 #elif defined GNULIB_POSIXCHECK
99 (GL_LINK_WARNING ("atoll is unportable - " \
100 "use gnulib module atoll for portability"), \
104 #if @GNULIB_CALLOC_POSIX@
105 # if !@HAVE_CALLOC_POSIX@
107 # define calloc rpl_calloc
108 extern void * calloc (size_t nmemb, size_t size);
110 #elif defined GNULIB_POSIXCHECK
112 # define calloc(n,s) \
113 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
114 "use gnulib module calloc-posix for portability"), \
118 #if @GNULIB_CANONICALIZE_FILE_NAME@
119 # if @REPLACE_CANONICALIZE_FILE_NAME@
120 # define canonicalize_file_name rpl_canonicalize_file_name
122 # if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@
123 extern char *canonicalize_file_name (const char *name);
125 #elif defined GNULIB_POSIXCHECK
126 # undef canonicalize_file_name
127 # define canonicalize_file_name(n) \
128 (GL_LINK_WARNING ("canonicalize_file_name is unportable - " \
129 "use gnulib module canonicalize-lgpl for portability"), \
130 canonicalize_file_name (n))
133 #if @GNULIB_GETLOADAVG@
134 # if !@HAVE_DECL_GETLOADAVG@
135 /* Store max(NELEM,3) load average numbers in LOADAVG[].
136 The three numbers are the load average of the last 1 minute, the last 5
137 minutes, and the last 15 minutes, respectively.
138 LOADAVG is an array of NELEM numbers. */
139 extern int getloadavg (double loadavg[], int nelem);
141 #elif defined GNULIB_POSIXCHECK
143 # define getloadavg(l,n) \
144 (GL_LINK_WARNING ("getloadavg is not portable - " \
145 "use gnulib module getloadavg for portability"), \
149 #if @GNULIB_GETSUBOPT@
150 /* Assuming *OPTIONP is a comma separated list of elements of the form
151 "token" or "token=value", getsubopt parses the first of these elements.
152 If the first element refers to a "token" that is member of the given
153 NULL-terminated array of tokens:
154 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
155 the first option and the comma, sets *VALUEP to the value of the
156 element (or NULL if it doesn't contain an "=" sign),
157 - It returns the index of the "token" in the given array of tokens.
158 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
159 For more details see the POSIX:2001 specification.
160 http://www.opengroup.org/susv3xsh/getsubopt.html */
161 # if !@HAVE_GETSUBOPT@
162 extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
164 #elif defined GNULIB_POSIXCHECK
166 # define getsubopt(o,t,v) \
167 (GL_LINK_WARNING ("getsubopt is unportable - " \
168 "use gnulib module getsubopt for portability"), \
172 #if @GNULIB_MALLOC_POSIX@
173 # if !@HAVE_MALLOC_POSIX@
175 # define malloc rpl_malloc
176 extern void * malloc (size_t size);
178 #elif defined GNULIB_POSIXCHECK
181 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
182 "use gnulib module malloc-posix for portability"), \
188 /* Create a unique temporary directory from TEMPLATE.
189 The last six characters of TEMPLATE must be "XXXXXX";
190 they are replaced with a string that makes the directory name unique.
191 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
192 The directory is created mode 700. */
193 extern char * mkdtemp (char * /*template*/);
195 #elif defined GNULIB_POSIXCHECK
197 # define mkdtemp(t) \
198 (GL_LINK_WARNING ("mkdtemp is unportable - " \
199 "use gnulib module mkdtemp for portability"), \
203 #if @GNULIB_MKOSTEMP@
204 # if !@HAVE_MKOSTEMP@
205 /* Create a unique temporary file from TEMPLATE.
206 The last six characters of TEMPLATE must be "XXXXXX";
207 they are replaced with a string that makes the file name unique.
208 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
209 and O_TEXT, O_BINARY (defined in "binary-io.h").
210 The file is then created, with the specified flags, ensuring it didn't exist
212 The file is created read-write (mask at least 0600 & ~umask), but it may be
213 world-readable and world-writable (mask 0666 & ~umask), depending on the
215 Returns the open file descriptor if successful, otherwise -1 and errno
217 extern int mkostemp (char * /*template*/, int /*flags*/);
219 #elif defined GNULIB_POSIXCHECK
221 # define mkostemp(t,f) \
222 (GL_LINK_WARNING ("mkostemp is unportable - " \
223 "use gnulib module mkostemp for portability"), \
227 #if @GNULIB_MKOSTEMPS@
228 # if !@HAVE_MKOSTEMPS@
229 /* Create a unique temporary file from TEMPLATE.
230 The last six characters of TEMPLATE before a suffix of length
231 SUFFIXLEN must be "XXXXXX";
232 they are replaced with a string that makes the file name unique.
233 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
234 and O_TEXT, O_BINARY (defined in "binary-io.h").
235 The file is then created, with the specified flags, ensuring it didn't exist
237 The file is created read-write (mask at least 0600 & ~umask), but it may be
238 world-readable and world-writable (mask 0666 & ~umask), depending on the
240 Returns the open file descriptor if successful, otherwise -1 and errno
242 extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/);
244 #elif defined GNULIB_POSIXCHECK
246 # define mkostemps(t,s,f) \
247 (GL_LINK_WARNING ("mkostemps is unportable - " \
248 "use gnulib module mkostemps for portability"), \
253 # if @REPLACE_MKSTEMP@
254 /* Create a unique temporary file from TEMPLATE.
255 The last six characters of TEMPLATE must be "XXXXXX";
256 they are replaced with a string that makes the file name unique.
257 The file is then created, ensuring it didn't exist before.
258 The file is created read-write (mask at least 0600 & ~umask), but it may be
259 world-readable and world-writable (mask 0666 & ~umask), depending on the
261 Returns the open file descriptor if successful, otherwise -1 and errno
263 # define mkstemp rpl_mkstemp
264 extern int mkstemp (char * /*template*/);
266 /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
269 #elif defined GNULIB_POSIXCHECK
271 # define mkstemp(t) \
272 (GL_LINK_WARNING ("mkstemp is unportable - " \
273 "use gnulib module mkstemp for portability"), \
277 #if @GNULIB_MKSTEMPS@
278 # if !@HAVE_MKSTEMPS@
279 /* Create a unique temporary file from TEMPLATE.
280 The last six characters of TEMPLATE prior to a suffix of length
281 SUFFIXLEN must be "XXXXXX";
282 they are replaced with a string that makes the file name unique.
283 The file is then created, ensuring it didn't exist before.
284 The file is created read-write (mask at least 0600 & ~umask), but it may be
285 world-readable and world-writable (mask 0666 & ~umask), depending on the
287 Returns the open file descriptor if successful, otherwise -1 and errno
289 extern int mkstemps (char * /*template*/, int /*suffixlen*/);
291 #elif defined GNULIB_POSIXCHECK
293 # define mkstemps(t,s) \
294 (GL_LINK_WARNING ("mkstemps is unportable - " \
295 "use gnulib module mkstemps for portability"), \
300 # if @REPLACE_PUTENV@
302 # define putenv rpl_putenv
303 extern int putenv (char *string);
307 #if @GNULIB_RANDOM_R@
308 # if !@HAVE_RANDOM_R@
311 # define RAND_MAX 2147483647
314 int srandom_r (unsigned int seed, struct random_data *rand_state);
315 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
316 struct random_data *rand_state);
317 int setstate_r (char *arg_state, struct random_data *rand_state);
318 int random_r (struct random_data *buf, int32_t *result);
320 #elif defined GNULIB_POSIXCHECK
322 # define random_r(b,r) \
323 (GL_LINK_WARNING ("random_r is unportable - " \
324 "use gnulib module random_r for portability"), \
327 # define initstate_r(s,b,sz,r) \
328 (GL_LINK_WARNING ("initstate_r is unportable - " \
329 "use gnulib module random_r for portability"), \
330 initstate_r (s,b,sz,r))
332 # define srandom_r(s,r) \
333 (GL_LINK_WARNING ("srandom_r is unportable - " \
334 "use gnulib module random_r for portability"), \
337 # define setstate_r(a,r) \
338 (GL_LINK_WARNING ("setstate_r is unportable - " \
339 "use gnulib module random_r for portability"), \
343 #if @GNULIB_REALLOC_POSIX@
344 # if !@HAVE_REALLOC_POSIX@
346 # define realloc rpl_realloc
347 extern void * realloc (void *ptr, size_t size);
349 #elif defined GNULIB_POSIXCHECK
351 # define realloc(p,s) \
352 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
353 "use gnulib module realloc-posix for portability"), \
357 #if @GNULIB_REALPATH@
358 # if @REPLACE_REALPATH@
359 # define realpath rpl_realpath
361 # if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
362 extern char *realpath (const char *name, char *resolved);
364 #elif defined GNULIB_POSIXCHECK
366 # define realpath(n,r) \
367 (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \
368 "canonicalize or canonicalize-lgpl for portability"), \
374 /* Test a user response to a question.
375 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
376 extern int rpmatch (const char *response);
378 #elif defined GNULIB_POSIXCHECK
380 # define rpmatch(r) \
381 (GL_LINK_WARNING ("rpmatch is unportable - " \
382 "use gnulib module rpmatch for portability"), \
388 /* Set NAME to VALUE in the environment.
389 If REPLACE is nonzero, overwrite an existing value. */
390 extern int setenv (const char *name, const char *value, int replace);
395 # if @REPLACE_STRTOD@
396 # define strtod rpl_strtod
398 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
399 /* Parse a double from STRING, updating ENDP if appropriate. */
400 extern double strtod (const char *str, char **endp);
402 #elif defined GNULIB_POSIXCHECK
404 # define strtod(s, e) \
405 (GL_LINK_WARNING ("strtod is unportable - " \
406 "use gnulib module strtod for portability"), \
412 /* Parse a signed integer whose textual representation starts at STRING.
413 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
414 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
416 If ENDPTR is not NULL, the address of the first byte after the integer is
418 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
420 extern long long strtoll (const char *string, char **endptr, int base);
422 #elif defined GNULIB_POSIXCHECK
424 # define strtoll(s,e,b) \
425 (GL_LINK_WARNING ("strtoll is unportable - " \
426 "use gnulib module strtoll for portability"), \
430 #if @GNULIB_STRTOULL@
431 # if !@HAVE_STRTOULL@
432 /* Parse an unsigned 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 ULLONG_MAX, and errno is set to
440 extern unsigned long long strtoull (const char *string, char **endptr, int base);
442 #elif defined GNULIB_POSIXCHECK
444 # define strtoull(s,e,b) \
445 (GL_LINK_WARNING ("strtoull is unportable - " \
446 "use gnulib module strtoull for portability"), \
450 #if @GNULIB_UNSETENV@
453 /* On some systems, unsetenv() returns void.
454 This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
455 # define unsetenv(name) ((unsetenv)(name), 0)
458 /* Remove the variable NAME from the environment. */
459 extern int unsetenv (const char *name);
467 #endif /* _GL_STDLIB_H */
468 #endif /* _GL_STDLIB_H */