Use Gnulib's `getaddrinfo' module.
[bpt/guile.git] / lib / stdlib.in.h
CommitLineData
f240aacb
LC
1/* A GNU-like <stdlib.h>.
2
61cd9dc9 3 Copyright (C) 1995, 2001-2004, 2006-2010 Free Software Foundation, Inc.
f240aacb
LC
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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
8912421c
LC
38/* NetBSD 5.0 mis-defines NULL. */
39#include <stddef.h>
f240aacb
LC
40
41/* Solaris declares getloadavg() in <sys/loadavg.h>. */
61cd9dc9 42#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
f240aacb
LC
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
61cd9dc9
LC
52#if !@HAVE_STRUCT_RANDOM_DATA@ || (@GNULIB_RANDOM_R@ && !@HAVE_RANDOM_R@) \
53 || defined GNULIB_POSIXCHECK
f240aacb
LC
54# include <stdint.h>
55#endif
56
57#if !@HAVE_STRUCT_RANDOM_DATA@
58struct random_data
59{
1cd4fffc
LC
60 int32_t *fptr; /* Front pointer. */
61 int32_t *rptr; /* Rear pointer. */
62 int32_t *state; /* Array of state values. */
63 int rand_type; /* Type of random number generator. */
64 int rand_deg; /* Degree of random number generator. */
65 int rand_sep; /* Distance between front and rear. */
66 int32_t *end_ptr; /* Pointer behind state table. */
f240aacb
LC
67};
68#endif
69
61cd9dc9
LC
70#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
71/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
72/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
73/* But avoid namespace pollution on glibc systems. */
74# include <unistd.h>
75#endif
f240aacb 76
1cd4fffc
LC
77/* The definition of _GL_ARG_NONNULL is copied here. */
78
61cd9dc9
LC
79/* The definition of _GL_WARN_ON_USE is copied here. */
80
f240aacb
LC
81
82/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
83#ifndef EXIT_SUCCESS
84# define EXIT_SUCCESS 0
85#endif
86/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
87 with proper operation of xargs. */
88#ifndef EXIT_FAILURE
89# define EXIT_FAILURE 1
90#elif EXIT_FAILURE != 1
91# undef EXIT_FAILURE
92# define EXIT_FAILURE 1
93#endif
94
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
8912421c
LC
100#if @GNULIB_ATOLL@
101# if !@HAVE_ATOLL@
102/* Parse a signed decimal integer.
103 Returns the value of the integer. Errors are not detected. */
1cd4fffc 104extern long long atoll (const char *string) _GL_ARG_NONNULL ((1));
f240aacb
LC
105# endif
106#elif defined GNULIB_POSIXCHECK
8912421c 107# undef atoll
61cd9dc9
LC
108# if HAVE_RAW_DECL_ATOLL
109_GL_WARN_ON_USE (atoll, "atoll is unportable - "
110 "use gnulib module atoll for portability");
111# endif
f240aacb
LC
112#endif
113
f240aacb
LC
114#if @GNULIB_CALLOC_POSIX@
115# if !@HAVE_CALLOC_POSIX@
116# undef calloc
117# define calloc rpl_calloc
118extern void * calloc (size_t nmemb, size_t size);
119# endif
120#elif defined GNULIB_POSIXCHECK
121# undef calloc
61cd9dc9
LC
122/* Assume calloc is always declared. */
123_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
124 "use gnulib module calloc-posix for portability");
f240aacb
LC
125#endif
126
8912421c
LC
127#if @GNULIB_CANONICALIZE_FILE_NAME@
128# if @REPLACE_CANONICALIZE_FILE_NAME@
129# define canonicalize_file_name rpl_canonicalize_file_name
130# endif
131# if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@
1cd4fffc 132extern char *canonicalize_file_name (const char *name) _GL_ARG_NONNULL ((1));
f240aacb
LC
133# endif
134#elif defined GNULIB_POSIXCHECK
8912421c 135# undef canonicalize_file_name
61cd9dc9
LC
136# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
137_GL_WARN_ON_USE (canonicalize_file_name, "canonicalize_file_name is unportable - "
138 "use gnulib module canonicalize-lgpl for portability");
139# endif
f240aacb
LC
140#endif
141
f240aacb
LC
142#if @GNULIB_GETLOADAVG@
143# if !@HAVE_DECL_GETLOADAVG@
144/* Store max(NELEM,3) load average numbers in LOADAVG[].
145 The three numbers are the load average of the last 1 minute, the last 5
146 minutes, and the last 15 minutes, respectively.
147 LOADAVG is an array of NELEM numbers. */
1cd4fffc 148extern int getloadavg (double loadavg[], int nelem) _GL_ARG_NONNULL ((1));
f240aacb
LC
149# endif
150#elif defined GNULIB_POSIXCHECK
151# undef getloadavg
61cd9dc9
LC
152# if HAVE_RAW_DECL_GETLOADAVG
153_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
154 "use gnulib module getloadavg for portability");
155# endif
f240aacb
LC
156#endif
157
f240aacb
LC
158#if @GNULIB_GETSUBOPT@
159/* Assuming *OPTIONP is a comma separated list of elements of the form
160 "token" or "token=value", getsubopt parses the first of these elements.
161 If the first element refers to a "token" that is member of the given
162 NULL-terminated array of tokens:
163 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
164 the first option and the comma, sets *VALUEP to the value of the
165 element (or NULL if it doesn't contain an "=" sign),
166 - It returns the index of the "token" in the given array of tokens.
167 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
168 For more details see the POSIX:2001 specification.
169 http://www.opengroup.org/susv3xsh/getsubopt.html */
170# if !@HAVE_GETSUBOPT@
1cd4fffc
LC
171extern int getsubopt (char **optionp, char *const *tokens, char **valuep)
172 _GL_ARG_NONNULL ((1, 2, 3));
f240aacb
LC
173# endif
174#elif defined GNULIB_POSIXCHECK
175# undef getsubopt
61cd9dc9
LC
176# if HAVE_RAW_DECL_GETSUBOPT
177_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - "
178 "use gnulib module getsubopt for portability");
179# endif
f240aacb
LC
180#endif
181
8912421c
LC
182#if @GNULIB_MALLOC_POSIX@
183# if !@HAVE_MALLOC_POSIX@
184# undef malloc
185# define malloc rpl_malloc
186extern void * malloc (size_t size);
187# endif
188#elif defined GNULIB_POSIXCHECK
189# undef malloc
61cd9dc9
LC
190/* Assume malloc is always declared. */
191_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
192 "use gnulib module malloc-posix for portability");
8912421c 193#endif
f240aacb
LC
194
195#if @GNULIB_MKDTEMP@
196# if !@HAVE_MKDTEMP@
197/* Create a unique temporary directory from TEMPLATE.
198 The last six characters of TEMPLATE must be "XXXXXX";
199 they are replaced with a string that makes the directory name unique.
200 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
201 The directory is created mode 700. */
1cd4fffc 202extern char * mkdtemp (char * /*template*/) _GL_ARG_NONNULL ((1));
f240aacb
LC
203# endif
204#elif defined GNULIB_POSIXCHECK
205# undef mkdtemp
61cd9dc9
LC
206# if HAVE_RAW_DECL_MKDTEMP
207_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - "
208 "use gnulib module mkdtemp for portability");
209# endif
f240aacb
LC
210#endif
211
8912421c
LC
212#if @GNULIB_MKOSTEMP@
213# if !@HAVE_MKOSTEMP@
214/* Create a unique temporary file from TEMPLATE.
215 The last six characters of TEMPLATE must be "XXXXXX";
216 they are replaced with a string that makes the file name unique.
217 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
218 and O_TEXT, O_BINARY (defined in "binary-io.h").
219 The file is then created, with the specified flags, ensuring it didn't exist
220 before.
221 The file is created read-write (mask at least 0600 & ~umask), but it may be
222 world-readable and world-writable (mask 0666 & ~umask), depending on the
223 implementation.
224 Returns the open file descriptor if successful, otherwise -1 and errno
225 set. */
1cd4fffc 226extern int mkostemp (char * /*template*/, int /*flags*/) _GL_ARG_NONNULL ((1));
8912421c
LC
227# endif
228#elif defined GNULIB_POSIXCHECK
229# undef mkostemp
61cd9dc9
LC
230# if HAVE_RAW_DECL_MKOSTEMP
231_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - "
232 "use gnulib module mkostemp for portability");
233# endif
8912421c 234#endif
f240aacb 235
f29ded4b
LC
236#if @GNULIB_MKOSTEMPS@
237# if !@HAVE_MKOSTEMPS@
238/* Create a unique temporary file from TEMPLATE.
239 The last six characters of TEMPLATE before a suffix of length
240 SUFFIXLEN must be "XXXXXX";
241 they are replaced with a string that makes the file name unique.
242 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
243 and O_TEXT, O_BINARY (defined in "binary-io.h").
244 The file is then created, with the specified flags, ensuring it didn't exist
245 before.
246 The file is created read-write (mask at least 0600 & ~umask), but it may be
247 world-readable and world-writable (mask 0666 & ~umask), depending on the
248 implementation.
249 Returns the open file descriptor if successful, otherwise -1 and errno
250 set. */
1cd4fffc
LC
251extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/)
252 _GL_ARG_NONNULL ((1));
f29ded4b
LC
253# endif
254#elif defined GNULIB_POSIXCHECK
255# undef mkostemps
61cd9dc9
LC
256# if HAVE_RAW_DECL_MKOSTEMPS
257_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - "
258 "use gnulib module mkostemps for portability");
259# endif
f29ded4b
LC
260#endif
261
f240aacb
LC
262#if @GNULIB_MKSTEMP@
263# if @REPLACE_MKSTEMP@
264/* Create a unique temporary file from TEMPLATE.
265 The last six characters of TEMPLATE must be "XXXXXX";
266 they are replaced with a string that makes the file name unique.
267 The file is then created, ensuring it didn't exist before.
268 The file is created read-write (mask at least 0600 & ~umask), but it may be
269 world-readable and world-writable (mask 0666 & ~umask), depending on the
270 implementation.
271 Returns the open file descriptor if successful, otherwise -1 and errno
272 set. */
273# define mkstemp rpl_mkstemp
1cd4fffc 274extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1));
f240aacb
LC
275# endif
276#elif defined GNULIB_POSIXCHECK
277# undef mkstemp
61cd9dc9
LC
278# if HAVE_RAW_DECL_MKSTEMP
279_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - "
280 "use gnulib module mkstemp for portability");
281# endif
f240aacb
LC
282#endif
283
f29ded4b
LC
284#if @GNULIB_MKSTEMPS@
285# if !@HAVE_MKSTEMPS@
286/* Create a unique temporary file from TEMPLATE.
287 The last six characters of TEMPLATE prior to a suffix of length
288 SUFFIXLEN must be "XXXXXX";
289 they are replaced with a string that makes the file name unique.
290 The file is then created, ensuring it didn't exist before.
291 The file is created read-write (mask at least 0600 & ~umask), but it may be
292 world-readable and world-writable (mask 0666 & ~umask), depending on the
293 implementation.
294 Returns the open file descriptor if successful, otherwise -1 and errno
295 set. */
1cd4fffc
LC
296extern int mkstemps (char * /*template*/, int /*suffixlen*/)
297 _GL_ARG_NONNULL ((1));
f29ded4b
LC
298# endif
299#elif defined GNULIB_POSIXCHECK
300# undef mkstemps
61cd9dc9
LC
301# if HAVE_RAW_DECL_MKSTEMPS
302_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
303 "use gnulib module mkstemps for portability");
304# endif
f29ded4b
LC
305#endif
306
f240aacb
LC
307#if @GNULIB_PUTENV@
308# if @REPLACE_PUTENV@
309# undef putenv
310# define putenv rpl_putenv
1cd4fffc 311extern int putenv (char *string) _GL_ARG_NONNULL ((1));
f240aacb
LC
312# endif
313#endif
314
f240aacb
LC
315#if @GNULIB_RANDOM_R@
316# if !@HAVE_RANDOM_R@
317
318# ifndef RAND_MAX
319# define RAND_MAX 2147483647
320# endif
321
1cd4fffc
LC
322int srandom_r (unsigned int seed, struct random_data *rand_state)
323 _GL_ARG_NONNULL ((2));
f240aacb 324int initstate_r (unsigned int seed, char *buf, size_t buf_size,
1cd4fffc
LC
325 struct random_data *rand_state)
326 _GL_ARG_NONNULL ((2, 4));
327int setstate_r (char *arg_state, struct random_data *rand_state)
328 _GL_ARG_NONNULL ((1, 2));
329int random_r (struct random_data *buf, int32_t *result)
330 _GL_ARG_NONNULL ((1, 2));
f240aacb
LC
331# endif
332#elif defined GNULIB_POSIXCHECK
333# undef random_r
61cd9dc9
LC
334# if HAVE_RAW_DECL_RANDOM_R
335_GL_WARN_ON_USE (random_r, "random_r is unportable - "
336 "use gnulib module random_r for portability");
337# endif
f240aacb 338# undef initstate_r
61cd9dc9
LC
339# if HAVE_RAW_DECL_INITSTATE_R
340_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - "
341 "use gnulib module random_r for portability");
342# endif
f240aacb 343# undef srandom_r
61cd9dc9
LC
344# if HAVE_RAW_DECL_SRANDOM_R
345_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - "
346 "use gnulib module random_r for portability");
347# endif
f240aacb 348# undef setstate_r
61cd9dc9
LC
349# if HAVE_RAW_DECL_SETSTATE_R
350_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
351 "use gnulib module random_r for portability");
352# endif
f240aacb
LC
353#endif
354
8912421c
LC
355#if @GNULIB_REALLOC_POSIX@
356# if !@HAVE_REALLOC_POSIX@
357# undef realloc
358# define realloc rpl_realloc
359extern void * realloc (void *ptr, size_t size);
360# endif
361#elif defined GNULIB_POSIXCHECK
362# undef realloc
61cd9dc9
LC
363/* Assume realloc is always declared. */
364_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
365 "use gnulib module realloc-posix for portability");
8912421c
LC
366#endif
367
368#if @GNULIB_REALPATH@
369# if @REPLACE_REALPATH@
370# define realpath rpl_realpath
371# endif
372# if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
1cd4fffc 373extern char *realpath (const char *name, char *resolved) _GL_ARG_NONNULL ((1));
8912421c
LC
374# endif
375#elif defined GNULIB_POSIXCHECK
376# undef realpath
61cd9dc9
LC
377# if HAVE_RAW_DECL_REALPATH
378_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module "
379 "canonicalize or canonicalize-lgpl for portability");
380# endif
8912421c 381#endif
f240aacb
LC
382
383#if @GNULIB_RPMATCH@
384# if !@HAVE_RPMATCH@
385/* Test a user response to a question.
386 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
1cd4fffc 387extern int rpmatch (const char *response) _GL_ARG_NONNULL ((1));
f240aacb
LC
388# endif
389#elif defined GNULIB_POSIXCHECK
390# undef rpmatch
61cd9dc9
LC
391# if HAVE_RAW_DECL_RPMATCH
392_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - "
393 "use gnulib module rpmatch for portability");
394# endif
f240aacb
LC
395#endif
396
f240aacb 397#if @GNULIB_SETENV@
4f02b98d
LC
398# if @REPLACE_SETENV@
399# undef setenv
400# define setenv rpl_setenv
401# endif
402# if !@HAVE_SETENV@ || @REPLACE_SETENV@
f240aacb
LC
403/* Set NAME to VALUE in the environment.
404 If REPLACE is nonzero, overwrite an existing value. */
1cd4fffc
LC
405extern int setenv (const char *name, const char *value, int replace)
406 _GL_ARG_NONNULL ((1));
f240aacb 407# endif
4f02b98d
LC
408#elif defined GNULIB_POSIXCHECK
409# undef setenv
61cd9dc9
LC
410# if HAVE_RAW_DECL_SETENV
411_GL_WARN_ON_USE (setenv, "setenv is unportable - "
412 "use gnulib module setenv for portability");
413# endif
f240aacb
LC
414#endif
415
f240aacb
LC
416#if @GNULIB_STRTOD@
417# if @REPLACE_STRTOD@
418# define strtod rpl_strtod
419# endif
420# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
421 /* Parse a double from STRING, updating ENDP if appropriate. */
1cd4fffc 422extern double strtod (const char *str, char **endp) _GL_ARG_NONNULL ((1));
f240aacb
LC
423# endif
424#elif defined GNULIB_POSIXCHECK
425# undef strtod
61cd9dc9
LC
426# if HAVE_RAW_DECL_STRTOD
427_GL_WARN_ON_USE (strtod, "strtod is unportable - "
428 "use gnulib module strtod for portability");
429# endif
f240aacb
LC
430#endif
431
f240aacb
LC
432#if @GNULIB_STRTOLL@
433# if !@HAVE_STRTOLL@
434/* Parse a signed integer whose textual representation starts at STRING.
435 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
436 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
437 "0x").
438 If ENDPTR is not NULL, the address of the first byte after the integer is
439 stored in *ENDPTR.
440 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
441 to ERANGE. */
1cd4fffc
LC
442extern long long strtoll (const char *string, char **endptr, int base)
443 _GL_ARG_NONNULL ((1));
f240aacb
LC
444# endif
445#elif defined GNULIB_POSIXCHECK
446# undef strtoll
61cd9dc9
LC
447# if HAVE_RAW_DECL_STRTOLL
448_GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
449 "use gnulib module strtoll for portability");
450# endif
f240aacb
LC
451#endif
452
f240aacb
LC
453#if @GNULIB_STRTOULL@
454# if !@HAVE_STRTOULL@
455/* Parse an unsigned integer whose textual representation starts at STRING.
456 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
457 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
458 "0x").
459 If ENDPTR is not NULL, the address of the first byte after the integer is
460 stored in *ENDPTR.
461 Upon overflow, the return value is ULLONG_MAX, and errno is set to
462 ERANGE. */
1cd4fffc
LC
463extern unsigned long long strtoull (const char *string, char **endptr, int base)
464 _GL_ARG_NONNULL ((1));
f240aacb
LC
465# endif
466#elif defined GNULIB_POSIXCHECK
467# undef strtoull
61cd9dc9
LC
468# if HAVE_RAW_DECL_STRTOULL
469_GL_WARN_ON_USE (strtoull, "strtoull is unportable - "
470 "use gnulib module strtoull for portability");
471# endif
f240aacb
LC
472#endif
473
8912421c 474#if @GNULIB_UNSETENV@
4f02b98d
LC
475# if @REPLACE_UNSETENV@
476# undef unsetenv
477# define unsetenv rpl_unsetenv
478# endif
479# if !@HAVE_UNSETENV@ || @REPLACE_UNSETENV@
8912421c 480/* Remove the variable NAME from the environment. */
1cd4fffc 481extern int unsetenv (const char *name) _GL_ARG_NONNULL ((1));
8912421c 482# endif
4f02b98d
LC
483#elif defined GNULIB_POSIXCHECK
484# undef unsetenv
61cd9dc9
LC
485# if HAVE_RAW_DECL_UNSETENV
486_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
487 "use gnulib module unsetenv for portability");
488# endif
8912421c 489#endif
f240aacb
LC
490
491#ifdef __cplusplus
492}
493#endif
494
495#endif /* _GL_STDLIB_H */
496#endif /* _GL_STDLIB_H */
497#endif