Document trailing whitespace policy.
[bpt/guile.git] / lib / stdlib.in.h
CommitLineData
f240aacb
LC
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 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>. */
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{
1cd4fffc
LC
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. */
f240aacb
LC
66};
67#endif
68
69/* The definition of GL_LINK_WARNING is copied here. */
70
1cd4fffc
LC
71/* The definition of _GL_ARG_NONNULL is copied here. */
72
f240aacb
LC
73
74/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
75#ifndef EXIT_SUCCESS
76# define EXIT_SUCCESS 0
77#endif
78/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
79 with proper operation of xargs. */
80#ifndef EXIT_FAILURE
81# define EXIT_FAILURE 1
82#elif EXIT_FAILURE != 1
83# undef EXIT_FAILURE
84# define EXIT_FAILURE 1
85#endif
86
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
8912421c
LC
92#if @GNULIB_ATOLL@
93# if !@HAVE_ATOLL@
94/* Parse a signed decimal integer.
95 Returns the value of the integer. Errors are not detected. */
1cd4fffc 96extern long long atoll (const char *string) _GL_ARG_NONNULL ((1));
f240aacb
LC
97# endif
98#elif defined GNULIB_POSIXCHECK
8912421c
LC
99# undef atoll
100# define atoll(s) \
101 (GL_LINK_WARNING ("atoll is unportable - " \
102 "use gnulib module atoll for portability"), \
103 atoll (s))
f240aacb
LC
104#endif
105
f240aacb
LC
106#if @GNULIB_CALLOC_POSIX@
107# if !@HAVE_CALLOC_POSIX@
108# undef calloc
109# define calloc rpl_calloc
110extern void * calloc (size_t nmemb, size_t size);
111# endif
112#elif defined GNULIB_POSIXCHECK
113# undef calloc
114# define calloc(n,s) \
115 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
116 "use gnulib module calloc-posix for portability"), \
117 calloc (n, s))
118#endif
119
8912421c
LC
120#if @GNULIB_CANONICALIZE_FILE_NAME@
121# if @REPLACE_CANONICALIZE_FILE_NAME@
122# define canonicalize_file_name rpl_canonicalize_file_name
123# endif
124# if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@
1cd4fffc 125extern char *canonicalize_file_name (const char *name) _GL_ARG_NONNULL ((1));
f240aacb
LC
126# endif
127#elif defined GNULIB_POSIXCHECK
8912421c
LC
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))
f240aacb
LC
133#endif
134
f240aacb
LC
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. */
1cd4fffc 141extern int getloadavg (double loadavg[], int nelem) _GL_ARG_NONNULL ((1));
f240aacb
LC
142# endif
143#elif defined GNULIB_POSIXCHECK
144# undef getloadavg
145# define getloadavg(l,n) \
146 (GL_LINK_WARNING ("getloadavg is not portable - " \
147 "use gnulib module getloadavg for portability"), \
148 getloadavg (l, n))
149#endif
150
f240aacb
LC
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@
1cd4fffc
LC
164extern int getsubopt (char **optionp, char *const *tokens, char **valuep)
165 _GL_ARG_NONNULL ((1, 2, 3));
f240aacb
LC
166# endif
167#elif defined GNULIB_POSIXCHECK
168# undef getsubopt
169# define getsubopt(o,t,v) \
170 (GL_LINK_WARNING ("getsubopt is unportable - " \
171 "use gnulib module getsubopt for portability"), \
172 getsubopt (o, t, v))
173#endif
174
8912421c
LC
175#if @GNULIB_MALLOC_POSIX@
176# if !@HAVE_MALLOC_POSIX@
177# undef malloc
178# define malloc rpl_malloc
179extern void * malloc (size_t size);
180# endif
181#elif defined GNULIB_POSIXCHECK
182# undef malloc
183# define malloc(s) \
184 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
185 "use gnulib module malloc-posix for portability"), \
186 malloc (s))
187#endif
f240aacb
LC
188
189#if @GNULIB_MKDTEMP@
190# if !@HAVE_MKDTEMP@
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. */
1cd4fffc 196extern char * mkdtemp (char * /*template*/) _GL_ARG_NONNULL ((1));
f240aacb
LC
197# endif
198#elif defined GNULIB_POSIXCHECK
199# undef mkdtemp
200# define mkdtemp(t) \
201 (GL_LINK_WARNING ("mkdtemp is unportable - " \
202 "use gnulib module mkdtemp for portability"), \
203 mkdtemp (t))
204#endif
205
8912421c
LC
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
214 before.
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
217 implementation.
218 Returns the open file descriptor if successful, otherwise -1 and errno
219 set. */
1cd4fffc 220extern int mkostemp (char * /*template*/, int /*flags*/) _GL_ARG_NONNULL ((1));
8912421c
LC
221# endif
222#elif defined GNULIB_POSIXCHECK
223# undef mkostemp
224# define mkostemp(t,f) \
225 (GL_LINK_WARNING ("mkostemp is unportable - " \
226 "use gnulib module mkostemp for portability"), \
227 mkostemp (t, f))
228#endif
f240aacb 229
f29ded4b
LC
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
239 before.
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
242 implementation.
243 Returns the open file descriptor if successful, otherwise -1 and errno
244 set. */
1cd4fffc
LC
245extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/)
246 _GL_ARG_NONNULL ((1));
f29ded4b
LC
247# endif
248#elif defined GNULIB_POSIXCHECK
249# undef mkostemps
250# define mkostemps(t,s,f) \
251 (GL_LINK_WARNING ("mkostemps is unportable - " \
252 "use gnulib module mkostemps for portability"), \
253 mkostemps (t, s, f))
254#endif
255
f240aacb
LC
256#if @GNULIB_MKSTEMP@
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
264 implementation.
265 Returns the open file descriptor if successful, otherwise -1 and errno
266 set. */
267# define mkstemp rpl_mkstemp
1cd4fffc 268extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1));
f240aacb
LC
269# else
270/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
271# include <unistd.h>
272# endif
273#elif defined GNULIB_POSIXCHECK
274# undef mkstemp
275# define mkstemp(t) \
276 (GL_LINK_WARNING ("mkstemp is unportable - " \
277 "use gnulib module mkstemp for portability"), \
278 mkstemp (t))
279#endif
280
f29ded4b
LC
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
290 implementation.
291 Returns the open file descriptor if successful, otherwise -1 and errno
292 set. */
1cd4fffc
LC
293extern int mkstemps (char * /*template*/, int /*suffixlen*/)
294 _GL_ARG_NONNULL ((1));
f29ded4b
LC
295# endif
296#elif defined GNULIB_POSIXCHECK
297# undef mkstemps
298# define mkstemps(t,s) \
299 (GL_LINK_WARNING ("mkstemps is unportable - " \
300 "use gnulib module mkstemps for portability"), \
301 mkstemps (t, s))
302#endif
303
f240aacb
LC
304#if @GNULIB_PUTENV@
305# if @REPLACE_PUTENV@
306# undef putenv
307# define putenv rpl_putenv
1cd4fffc 308extern int putenv (char *string) _GL_ARG_NONNULL ((1));
f240aacb
LC
309# endif
310#endif
311
f240aacb
LC
312#if @GNULIB_RANDOM_R@
313# if !@HAVE_RANDOM_R@
314
315# ifndef RAND_MAX
316# define RAND_MAX 2147483647
317# endif
318
1cd4fffc
LC
319int srandom_r (unsigned int seed, struct random_data *rand_state)
320 _GL_ARG_NONNULL ((2));
f240aacb 321int initstate_r (unsigned int seed, char *buf, size_t buf_size,
1cd4fffc
LC
322 struct random_data *rand_state)
323 _GL_ARG_NONNULL ((2, 4));
324int setstate_r (char *arg_state, struct random_data *rand_state)
325 _GL_ARG_NONNULL ((1, 2));
326int random_r (struct random_data *buf, int32_t *result)
327 _GL_ARG_NONNULL ((1, 2));
f240aacb
LC
328# endif
329#elif defined GNULIB_POSIXCHECK
330# undef random_r
1cd4fffc 331# define random_r(b,r) \
f240aacb
LC
332 (GL_LINK_WARNING ("random_r is unportable - " \
333 "use gnulib module random_r for portability"), \
334 random_r (b,r))
335# undef initstate_r
1cd4fffc 336# define initstate_r(s,b,sz,r) \
f240aacb
LC
337 (GL_LINK_WARNING ("initstate_r is unportable - " \
338 "use gnulib module random_r for portability"), \
339 initstate_r (s,b,sz,r))
340# undef srandom_r
1cd4fffc 341# define srandom_r(s,r) \
f240aacb
LC
342 (GL_LINK_WARNING ("srandom_r is unportable - " \
343 "use gnulib module random_r for portability"), \
344 srandom_r (s,r))
345# undef setstate_r
1cd4fffc 346# define setstate_r(a,r) \
f240aacb
LC
347 (GL_LINK_WARNING ("setstate_r is unportable - " \
348 "use gnulib module random_r for portability"), \
349 setstate_r (a,r))
350#endif
351
8912421c
LC
352#if @GNULIB_REALLOC_POSIX@
353# if !@HAVE_REALLOC_POSIX@
354# undef realloc
355# define realloc rpl_realloc
356extern void * realloc (void *ptr, size_t size);
357# endif
358#elif defined GNULIB_POSIXCHECK
359# undef realloc
360# define realloc(p,s) \
361 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
362 "use gnulib module realloc-posix for portability"), \
363 realloc (p, s))
364#endif
365
366#if @GNULIB_REALPATH@
367# if @REPLACE_REALPATH@
368# define realpath rpl_realpath
369# endif
370# if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
1cd4fffc 371extern char *realpath (const char *name, char *resolved) _GL_ARG_NONNULL ((1));
8912421c
LC
372# endif
373#elif defined GNULIB_POSIXCHECK
374# undef realpath
375# define realpath(n,r) \
376 (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \
377 "canonicalize or canonicalize-lgpl for portability"), \
378 realpath (n, r))
379#endif
f240aacb
LC
380
381#if @GNULIB_RPMATCH@
382# if !@HAVE_RPMATCH@
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. */
1cd4fffc 385extern int rpmatch (const char *response) _GL_ARG_NONNULL ((1));
f240aacb
LC
386# endif
387#elif defined GNULIB_POSIXCHECK
388# undef rpmatch
389# define rpmatch(r) \
390 (GL_LINK_WARNING ("rpmatch is unportable - " \
391 "use gnulib module rpmatch for portability"), \
392 rpmatch (r))
393#endif
394
f240aacb 395#if @GNULIB_SETENV@
4f02b98d
LC
396# if @REPLACE_SETENV@
397# undef setenv
398# define setenv rpl_setenv
399# endif
400# if !@HAVE_SETENV@ || @REPLACE_SETENV@
f240aacb
LC
401/* Set NAME to VALUE in the environment.
402 If REPLACE is nonzero, overwrite an existing value. */
1cd4fffc
LC
403extern int setenv (const char *name, const char *value, int replace)
404 _GL_ARG_NONNULL ((1));
f240aacb 405# endif
4f02b98d
LC
406#elif defined GNULIB_POSIXCHECK
407# undef setenv
408# define setenv(n,v,o) \
409 (GL_LINK_WARNING ("setenv is unportable - " \
410 "use gnulib module setenv for portability"), \
411 setenv (n, v, o))
f240aacb
LC
412#endif
413
f240aacb
LC
414#if @GNULIB_STRTOD@
415# if @REPLACE_STRTOD@
416# define strtod rpl_strtod
417# endif
418# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
419 /* Parse a double from STRING, updating ENDP if appropriate. */
1cd4fffc 420extern double strtod (const char *str, char **endp) _GL_ARG_NONNULL ((1));
f240aacb
LC
421# endif
422#elif defined GNULIB_POSIXCHECK
423# undef strtod
424# define strtod(s, e) \
425 (GL_LINK_WARNING ("strtod is unportable - " \
426 "use gnulib module strtod for portability"), \
427 strtod (s, e))
428#endif
429
f240aacb
LC
430#if @GNULIB_STRTOLL@
431# if !@HAVE_STRTOLL@
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
435 "0x").
436 If ENDPTR is not NULL, the address of the first byte after the integer is
437 stored in *ENDPTR.
438 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
439 to ERANGE. */
1cd4fffc
LC
440extern long long strtoll (const char *string, char **endptr, int base)
441 _GL_ARG_NONNULL ((1));
f240aacb
LC
442# endif
443#elif defined GNULIB_POSIXCHECK
444# undef strtoll
445# define strtoll(s,e,b) \
446 (GL_LINK_WARNING ("strtoll is unportable - " \
447 "use gnulib module strtoll for portability"), \
448 strtoll (s, e, b))
449#endif
450
f240aacb
LC
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
456 "0x").
457 If ENDPTR is not NULL, the address of the first byte after the integer is
458 stored in *ENDPTR.
459 Upon overflow, the return value is ULLONG_MAX, and errno is set to
460 ERANGE. */
1cd4fffc
LC
461extern unsigned long long strtoull (const char *string, char **endptr, int base)
462 _GL_ARG_NONNULL ((1));
f240aacb
LC
463# endif
464#elif defined GNULIB_POSIXCHECK
465# undef strtoull
466# define strtoull(s,e,b) \
467 (GL_LINK_WARNING ("strtoull is unportable - " \
468 "use gnulib module strtoull for portability"), \
469 strtoull (s, e, b))
470#endif
471
8912421c 472#if @GNULIB_UNSETENV@
4f02b98d
LC
473# if @REPLACE_UNSETENV@
474# undef unsetenv
475# define unsetenv rpl_unsetenv
476# endif
477# if !@HAVE_UNSETENV@ || @REPLACE_UNSETENV@
8912421c 478/* Remove the variable NAME from the environment. */
1cd4fffc 479extern int unsetenv (const char *name) _GL_ARG_NONNULL ((1));
8912421c 480# endif
4f02b98d
LC
481#elif defined GNULIB_POSIXCHECK
482# undef unsetenv
483# define unsetenv(n) \
484 (GL_LINK_WARNING ("unsetenv is unportable - " \
485 "use gnulib module unsetenv for portability"), \
486 unsetenv (n))
8912421c 487#endif
f240aacb
LC
488
489#ifdef __cplusplus
490}
491#endif
492
493#endif /* _GL_STDLIB_H */
494#endif /* _GL_STDLIB_H */
495#endif