Fix typo in today's commit.
[gnulib.git] / lib / stdlib.in.h
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@ || defined GNULIB_POSIXCHECK) && @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      || defined GNULIB_POSIXCHECK)
54 # include <stdint.h>
55 #endif
56
57 #if !@HAVE_STRUCT_RANDOM_DATA@
58 struct random_data
59 {
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.  */
67 };
68 #endif
69
70 #if @GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK
71 /* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
72 /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt.  */
73 # include <unistd.h>
74 #endif
75
76 /* The definition of GL_LINK_WARNING is copied here.  */
77
78 /* The definition of _GL_ARG_NONNULL is copied here.  */
79
80
81 /* Some systems do not define EXIT_*, despite otherwise supporting C89.  */
82 #ifndef EXIT_SUCCESS
83 # define EXIT_SUCCESS 0
84 #endif
85 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
86    with proper operation of xargs.  */
87 #ifndef EXIT_FAILURE
88 # define EXIT_FAILURE 1
89 #elif EXIT_FAILURE != 1
90 # undef EXIT_FAILURE
91 # define EXIT_FAILURE 1
92 #endif
93
94
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98
99 #if @GNULIB_ATOLL@
100 # if !@HAVE_ATOLL@
101 /* Parse a signed decimal integer.
102    Returns the value of the integer.  Errors are not detected.  */
103 extern long long atoll (const char *string) _GL_ARG_NONNULL ((1));
104 # endif
105 #elif defined GNULIB_POSIXCHECK
106 # undef atoll
107 # define atoll(s) \
108     (GL_LINK_WARNING ("atoll is unportable - " \
109                       "use gnulib module atoll for portability"), \
110      atoll (s))
111 #endif
112
113 #if @GNULIB_CALLOC_POSIX@
114 # if !@HAVE_CALLOC_POSIX@
115 #  undef calloc
116 #  define calloc rpl_calloc
117 extern void * calloc (size_t nmemb, size_t size);
118 # endif
119 #elif defined GNULIB_POSIXCHECK
120 # undef calloc
121 # define calloc(n,s) \
122     (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
123                       "use gnulib module calloc-posix for portability"), \
124      calloc (n, s))
125 #endif
126
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@
132 extern char *canonicalize_file_name (const char *name) _GL_ARG_NONNULL ((1));
133 # endif
134 #elif defined GNULIB_POSIXCHECK
135 # undef canonicalize_file_name
136 # define canonicalize_file_name(n)                        \
137     (GL_LINK_WARNING ("canonicalize_file_name is unportable - " \
138                       "use gnulib module canonicalize-lgpl for portability"), \
139      canonicalize_file_name (n))
140 #endif
141
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.  */
148 extern int getloadavg (double loadavg[], int nelem) _GL_ARG_NONNULL ((1));
149 # endif
150 #elif defined GNULIB_POSIXCHECK
151 # undef getloadavg
152 # define getloadavg(l,n) \
153     (GL_LINK_WARNING ("getloadavg is not portable - " \
154                       "use gnulib module getloadavg for portability"), \
155      getloadavg (l, n))
156 #endif
157
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@
171 extern int getsubopt (char **optionp, char *const *tokens, char **valuep)
172      _GL_ARG_NONNULL ((1, 2, 3));
173 # endif
174 #elif defined GNULIB_POSIXCHECK
175 # undef getsubopt
176 # define getsubopt(o,t,v) \
177     (GL_LINK_WARNING ("getsubopt is unportable - " \
178                       "use gnulib module getsubopt for portability"), \
179      getsubopt (o, t, v))
180 #endif
181
182 #if @GNULIB_MALLOC_POSIX@
183 # if !@HAVE_MALLOC_POSIX@
184 #  undef malloc
185 #  define malloc rpl_malloc
186 extern void * malloc (size_t size);
187 # endif
188 #elif defined GNULIB_POSIXCHECK
189 # undef malloc
190 # define malloc(s) \
191     (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
192                       "use gnulib module malloc-posix for portability"), \
193      malloc (s))
194 #endif
195
196 #if @GNULIB_MKDTEMP@
197 # if !@HAVE_MKDTEMP@
198 /* Create a unique temporary directory from TEMPLATE.
199    The last six characters of TEMPLATE must be "XXXXXX";
200    they are replaced with a string that makes the directory name unique.
201    Returns TEMPLATE, or a null pointer if it cannot get a unique name.
202    The directory is created mode 700.  */
203 extern char * mkdtemp (char * /*template*/) _GL_ARG_NONNULL ((1));
204 # endif
205 #elif defined GNULIB_POSIXCHECK
206 # undef mkdtemp
207 # define mkdtemp(t) \
208     (GL_LINK_WARNING ("mkdtemp is unportable - " \
209                       "use gnulib module mkdtemp for portability"), \
210      mkdtemp (t))
211 #endif
212
213 #if @GNULIB_MKOSTEMP@
214 # if !@HAVE_MKOSTEMP@
215 /* Create a unique temporary file from TEMPLATE.
216    The last six characters of TEMPLATE must be "XXXXXX";
217    they are replaced with a string that makes the file name unique.
218    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
219    and O_TEXT, O_BINARY (defined in "binary-io.h").
220    The file is then created, with the specified flags, ensuring it didn't exist
221    before.
222    The file is created read-write (mask at least 0600 & ~umask), but it may be
223    world-readable and world-writable (mask 0666 & ~umask), depending on the
224    implementation.
225    Returns the open file descriptor if successful, otherwise -1 and errno
226    set.  */
227 extern int mkostemp (char * /*template*/, int /*flags*/) _GL_ARG_NONNULL ((1));
228 # endif
229 #elif defined GNULIB_POSIXCHECK
230 # undef mkostemp
231 # define mkostemp(t,f) \
232     (GL_LINK_WARNING ("mkostemp is unportable - " \
233                       "use gnulib module mkostemp for portability"), \
234      mkostemp (t, f))
235 #endif
236
237 #if @GNULIB_MKOSTEMPS@
238 # if !@HAVE_MKOSTEMPS@
239 /* Create a unique temporary file from TEMPLATE.
240    The last six characters of TEMPLATE before a suffix of length
241    SUFFIXLEN must be "XXXXXX";
242    they are replaced with a string that makes the file name unique.
243    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
244    and O_TEXT, O_BINARY (defined in "binary-io.h").
245    The file is then created, with the specified flags, ensuring it didn't exist
246    before.
247    The file is created read-write (mask at least 0600 & ~umask), but it may be
248    world-readable and world-writable (mask 0666 & ~umask), depending on the
249    implementation.
250    Returns the open file descriptor if successful, otherwise -1 and errno
251    set.  */
252 extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/)
253      _GL_ARG_NONNULL ((1));
254 # endif
255 #elif defined GNULIB_POSIXCHECK
256 # undef mkostemps
257 # define mkostemps(t,s,f)                          \
258     (GL_LINK_WARNING ("mkostemps is unportable - " \
259                       "use gnulib module mkostemps for portability"), \
260      mkostemps (t, s, f))
261 #endif
262
263 #if @GNULIB_MKSTEMP@
264 # if @REPLACE_MKSTEMP@
265 /* Create a unique temporary file from TEMPLATE.
266    The last six characters of TEMPLATE must be "XXXXXX";
267    they are replaced with a string that makes the file name unique.
268    The file is then created, ensuring it didn't exist before.
269    The file is created read-write (mask at least 0600 & ~umask), but it may be
270    world-readable and world-writable (mask 0666 & ~umask), depending on the
271    implementation.
272    Returns the open file descriptor if successful, otherwise -1 and errno
273    set.  */
274 #  define mkstemp rpl_mkstemp
275 extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1));
276 # endif
277 #elif defined GNULIB_POSIXCHECK
278 # undef mkstemp
279 # define mkstemp(t) \
280     (GL_LINK_WARNING ("mkstemp is unportable - " \
281                       "use gnulib module mkstemp for portability"), \
282      mkstemp (t))
283 #endif
284
285 #if @GNULIB_MKSTEMPS@
286 # if !@HAVE_MKSTEMPS@
287 /* Create a unique temporary file from TEMPLATE.
288    The last six characters of TEMPLATE prior to a suffix of length
289    SUFFIXLEN must be "XXXXXX";
290    they are replaced with a string that makes the file name unique.
291    The file is then created, ensuring it didn't exist before.
292    The file is created read-write (mask at least 0600 & ~umask), but it may be
293    world-readable and world-writable (mask 0666 & ~umask), depending on the
294    implementation.
295    Returns the open file descriptor if successful, otherwise -1 and errno
296    set.  */
297 extern int mkstemps (char * /*template*/, int /*suffixlen*/)
298      _GL_ARG_NONNULL ((1));
299 # endif
300 #elif defined GNULIB_POSIXCHECK
301 # undef mkstemps
302 # define mkstemps(t,s)                             \
303     (GL_LINK_WARNING ("mkstemps is unportable - " \
304                       "use gnulib module mkstemps for portability"), \
305      mkstemps (t, s))
306 #endif
307
308 #if @GNULIB_PUTENV@
309 # if @REPLACE_PUTENV@
310 #  undef putenv
311 #  define putenv rpl_putenv
312 extern int putenv (char *string) _GL_ARG_NONNULL ((1));
313 # endif
314 #endif
315
316 #if @GNULIB_RANDOM_R@
317 # if !@HAVE_RANDOM_R@
318
319 #  ifndef RAND_MAX
320 #   define RAND_MAX 2147483647
321 #  endif
322
323 int srandom_r (unsigned int seed, struct random_data *rand_state)
324      _GL_ARG_NONNULL ((2));
325 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
326                  struct random_data *rand_state)
327      _GL_ARG_NONNULL ((2, 4));
328 int setstate_r (char *arg_state, struct random_data *rand_state)
329      _GL_ARG_NONNULL ((1, 2));
330 int random_r (struct random_data *buf, int32_t *result)
331      _GL_ARG_NONNULL ((1, 2));
332 # endif
333 #elif defined GNULIB_POSIXCHECK
334 # undef random_r
335 # define random_r(b,r)                            \
336     (GL_LINK_WARNING ("random_r is unportable - " \
337                       "use gnulib module random_r for portability"), \
338      random_r (b,r))
339 # undef initstate_r
340 # define initstate_r(s,b,sz,r)                       \
341     (GL_LINK_WARNING ("initstate_r is unportable - " \
342                       "use gnulib module random_r for portability"), \
343      initstate_r (s,b,sz,r))
344 # undef srandom_r
345 # define srandom_r(s,r)                            \
346     (GL_LINK_WARNING ("srandom_r is unportable - " \
347                       "use gnulib module random_r for portability"), \
348      srandom_r (s,r))
349 # undef setstate_r
350 # define setstate_r(a,r)                                    \
351     (GL_LINK_WARNING ("setstate_r is unportable - " \
352                       "use gnulib module random_r for portability"), \
353      setstate_r (a,r))
354 #endif
355
356 #if @GNULIB_REALLOC_POSIX@
357 # if !@HAVE_REALLOC_POSIX@
358 #  undef realloc
359 #  define realloc rpl_realloc
360 extern void * realloc (void *ptr, size_t size);
361 # endif
362 #elif defined GNULIB_POSIXCHECK
363 # undef realloc
364 # define realloc(p,s) \
365     (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
366                       "use gnulib module realloc-posix for portability"), \
367      realloc (p, s))
368 #endif
369
370 #if @GNULIB_REALPATH@
371 # if @REPLACE_REALPATH@
372 #  define realpath rpl_realpath
373 # endif
374 # if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
375 extern char *realpath (const char *name, char *resolved) _GL_ARG_NONNULL ((1));
376 # endif
377 #elif defined GNULIB_POSIXCHECK
378 # undef realpath
379 # define realpath(n,r)                        \
380     (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \
381                       "canonicalize or canonicalize-lgpl for portability"), \
382      realpath (n, r))
383 #endif
384
385 #if @GNULIB_RPMATCH@
386 # if !@HAVE_RPMATCH@
387 /* Test a user response to a question.
388    Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear.  */
389 extern int rpmatch (const char *response) _GL_ARG_NONNULL ((1));
390 # endif
391 #elif defined GNULIB_POSIXCHECK
392 # undef rpmatch
393 # define rpmatch(r) \
394     (GL_LINK_WARNING ("rpmatch is unportable - " \
395                       "use gnulib module rpmatch for portability"), \
396      rpmatch (r))
397 #endif
398
399 #if @GNULIB_SETENV@
400 # if @REPLACE_SETENV@
401 #  undef setenv
402 #  define setenv rpl_setenv
403 # endif
404 # if !@HAVE_SETENV@ || @REPLACE_SETENV@
405 /* Set NAME to VALUE in the environment.
406    If REPLACE is nonzero, overwrite an existing value.  */
407 extern int setenv (const char *name, const char *value, int replace)
408      _GL_ARG_NONNULL ((1));
409 # endif
410 #elif defined GNULIB_POSIXCHECK
411 # undef setenv
412 # define setenv(n,v,o)                                                  \
413     (GL_LINK_WARNING ("setenv is unportable - "                         \
414                       "use gnulib module setenv for portability"),      \
415      setenv (n, v, o))
416 #endif
417
418 #if @GNULIB_STRTOD@
419 # if @REPLACE_STRTOD@
420 #  define strtod rpl_strtod
421 # endif
422 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
423  /* Parse a double from STRING, updating ENDP if appropriate.  */
424 extern double strtod (const char *str, char **endp) _GL_ARG_NONNULL ((1));
425 # endif
426 #elif defined GNULIB_POSIXCHECK
427 # undef strtod
428 # define strtod(s, e)                           \
429     (GL_LINK_WARNING ("strtod is unportable - " \
430                       "use gnulib module strtod for portability"), \
431      strtod (s, e))
432 #endif
433
434 #if @GNULIB_STRTOLL@
435 # if !@HAVE_STRTOLL@
436 /* Parse a signed integer whose textual representation starts at STRING.
437    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
438    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
439    "0x").
440    If ENDPTR is not NULL, the address of the first byte after the integer is
441    stored in *ENDPTR.
442    Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
443    to ERANGE.  */
444 extern long long strtoll (const char *string, char **endptr, int base)
445      _GL_ARG_NONNULL ((1));
446 # endif
447 #elif defined GNULIB_POSIXCHECK
448 # undef strtoll
449 # define strtoll(s,e,b) \
450     (GL_LINK_WARNING ("strtoll is unportable - " \
451                       "use gnulib module strtoll for portability"), \
452      strtoll (s, e, b))
453 #endif
454
455 #if @GNULIB_STRTOULL@
456 # if !@HAVE_STRTOULL@
457 /* Parse an unsigned integer whose textual representation starts at STRING.
458    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
459    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
460    "0x").
461    If ENDPTR is not NULL, the address of the first byte after the integer is
462    stored in *ENDPTR.
463    Upon overflow, the return value is ULLONG_MAX, and errno is set to
464    ERANGE.  */
465 extern unsigned long long strtoull (const char *string, char **endptr, int base)
466      _GL_ARG_NONNULL ((1));
467 # endif
468 #elif defined GNULIB_POSIXCHECK
469 # undef strtoull
470 # define strtoull(s,e,b) \
471     (GL_LINK_WARNING ("strtoull is unportable - " \
472                       "use gnulib module strtoull for portability"), \
473      strtoull (s, e, b))
474 #endif
475
476 #if @GNULIB_UNSETENV@
477 # if @REPLACE_UNSETENV@
478 #  undef unsetenv
479 #  define unsetenv rpl_unsetenv
480 # endif
481 # if !@HAVE_UNSETENV@ || @REPLACE_UNSETENV@
482 /* Remove the variable NAME from the environment.  */
483 extern int unsetenv (const char *name) _GL_ARG_NONNULL ((1));
484 # endif
485 #elif defined GNULIB_POSIXCHECK
486 # undef unsetenv
487 # define unsetenv(n)                                                    \
488     (GL_LINK_WARNING ("unsetenv is unportable - "                       \
489                       "use gnulib module unsetenv for portability"),    \
490      unsetenv (n))
491 #endif
492
493 #ifdef __cplusplus
494 }
495 #endif
496
497 #endif /* _GL_STDLIB_H */
498 #endif /* _GL_STDLIB_H */
499 #endif