Imported Upstream version 1.3.14
[debian/gzip] / 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@ && @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@
57 struct random_data
58 {
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.  */
66 };
67 #endif
68
69 /* The definition of GL_LINK_WARNING is copied here.  */
70
71
72 /* Some systems do not define EXIT_*, despite otherwise supporting C89.  */
73 #ifndef EXIT_SUCCESS
74 # define EXIT_SUCCESS 0
75 #endif
76 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
77    with proper operation of xargs.  */
78 #ifndef EXIT_FAILURE
79 # define EXIT_FAILURE 1
80 #elif EXIT_FAILURE != 1
81 # undef EXIT_FAILURE
82 # define EXIT_FAILURE 1
83 #endif
84
85
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89
90 #if @GNULIB_ATOLL@
91 # if !@HAVE_ATOLL@
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);
95 # endif
96 #elif defined GNULIB_POSIXCHECK
97 # undef atoll
98 # define atoll(s) \
99     (GL_LINK_WARNING ("atoll is unportable - " \
100                       "use gnulib module atoll for portability"), \
101      atoll (s))
102 #endif
103
104 #if @GNULIB_CALLOC_POSIX@
105 # if !@HAVE_CALLOC_POSIX@
106 #  undef calloc
107 #  define calloc rpl_calloc
108 extern void * calloc (size_t nmemb, size_t size);
109 # endif
110 #elif defined GNULIB_POSIXCHECK
111 # undef calloc
112 # define calloc(n,s) \
113     (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
114                       "use gnulib module calloc-posix for portability"), \
115      calloc (n, s))
116 #endif
117
118 #if @GNULIB_CANONICALIZE_FILE_NAME@
119 # if @REPLACE_CANONICALIZE_FILE_NAME@
120 #  define canonicalize_file_name rpl_canonicalize_file_name
121 # endif
122 # if !@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@
123 extern char *canonicalize_file_name (const char *name);
124 # endif
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))
131 #endif
132
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);
140 # endif
141 #elif defined GNULIB_POSIXCHECK
142 # undef getloadavg
143 # define getloadavg(l,n) \
144     (GL_LINK_WARNING ("getloadavg is not portable - " \
145                       "use gnulib module getloadavg for portability"), \
146      getloadavg (l, n))
147 #endif
148
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);
163 # endif
164 #elif defined GNULIB_POSIXCHECK
165 # undef getsubopt
166 # define getsubopt(o,t,v) \
167     (GL_LINK_WARNING ("getsubopt is unportable - " \
168                       "use gnulib module getsubopt for portability"), \
169      getsubopt (o, t, v))
170 #endif
171
172 #if @GNULIB_MALLOC_POSIX@
173 # if !@HAVE_MALLOC_POSIX@
174 #  undef malloc
175 #  define malloc rpl_malloc
176 extern void * malloc (size_t size);
177 # endif
178 #elif defined GNULIB_POSIXCHECK
179 # undef malloc
180 # define malloc(s) \
181     (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
182                       "use gnulib module malloc-posix for portability"), \
183      malloc (s))
184 #endif
185
186 #if @GNULIB_MKDTEMP@
187 # if !@HAVE_MKDTEMP@
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*/);
194 # endif
195 #elif defined GNULIB_POSIXCHECK
196 # undef mkdtemp
197 # define mkdtemp(t) \
198     (GL_LINK_WARNING ("mkdtemp is unportable - " \
199                       "use gnulib module mkdtemp for portability"), \
200      mkdtemp (t))
201 #endif
202
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
211    before.
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
214    implementation.
215    Returns the open file descriptor if successful, otherwise -1 and errno
216    set.  */
217 extern int mkostemp (char * /*template*/, int /*flags*/);
218 # endif
219 #elif defined GNULIB_POSIXCHECK
220 # undef mkostemp
221 # define mkostemp(t,f) \
222     (GL_LINK_WARNING ("mkostemp is unportable - " \
223                       "use gnulib module mkostemp for portability"), \
224      mkostemp (t, f))
225 #endif
226
227 #if @GNULIB_MKSTEMP@
228 # if @REPLACE_MKSTEMP@
229 /* Create a unique temporary file from TEMPLATE.
230    The last six characters of TEMPLATE must be "XXXXXX";
231    they are replaced with a string that makes the file name unique.
232    The file is then created, ensuring it didn't exist before.
233    The file is created read-write (mask at least 0600 & ~umask), but it may be
234    world-readable and world-writable (mask 0666 & ~umask), depending on the
235    implementation.
236    Returns the open file descriptor if successful, otherwise -1 and errno
237    set.  */
238 #  define mkstemp rpl_mkstemp
239 extern int mkstemp (char * /*template*/);
240 # else
241 /* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
242 #  include <unistd.h>
243 # endif
244 #elif defined GNULIB_POSIXCHECK
245 # undef mkstemp
246 # define mkstemp(t) \
247     (GL_LINK_WARNING ("mkstemp is unportable - " \
248                       "use gnulib module mkstemp for portability"), \
249      mkstemp (t))
250 #endif
251
252 #if @GNULIB_PUTENV@
253 # if @REPLACE_PUTENV@
254 #  undef putenv
255 #  define putenv rpl_putenv
256 extern int putenv (char *string);
257 # endif
258 #endif
259
260 #if @GNULIB_RANDOM_R@
261 # if !@HAVE_RANDOM_R@
262
263 #  ifndef RAND_MAX
264 #   define RAND_MAX 2147483647
265 #  endif
266
267 int srandom_r (unsigned int seed, struct random_data *rand_state);
268 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
269                  struct random_data *rand_state);
270 int setstate_r (char *arg_state, struct random_data *rand_state);
271 int random_r (struct random_data *buf, int32_t *result);
272 # endif
273 #elif defined GNULIB_POSIXCHECK
274 # undef random_r
275 # define random_r(b,r)                            \
276     (GL_LINK_WARNING ("random_r is unportable - " \
277                       "use gnulib module random_r for portability"), \
278      random_r (b,r))
279 # undef initstate_r
280 # define initstate_r(s,b,sz,r)                       \
281     (GL_LINK_WARNING ("initstate_r is unportable - " \
282                       "use gnulib module random_r for portability"), \
283      initstate_r (s,b,sz,r))
284 # undef srandom_r
285 # define srandom_r(s,r)                            \
286     (GL_LINK_WARNING ("srandom_r is unportable - " \
287                       "use gnulib module random_r for portability"), \
288      srandom_r (s,r))
289 # undef setstate_r
290 # define setstate_r(a,r)                                    \
291     (GL_LINK_WARNING ("setstate_r is unportable - " \
292                       "use gnulib module random_r for portability"), \
293      setstate_r (a,r))
294 #endif
295
296 #if @GNULIB_REALLOC_POSIX@
297 # if !@HAVE_REALLOC_POSIX@
298 #  undef realloc
299 #  define realloc rpl_realloc
300 extern void * realloc (void *ptr, size_t size);
301 # endif
302 #elif defined GNULIB_POSIXCHECK
303 # undef realloc
304 # define realloc(p,s) \
305     (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
306                       "use gnulib module realloc-posix for portability"), \
307      realloc (p, s))
308 #endif
309
310 #if @GNULIB_REALPATH@
311 # if @REPLACE_REALPATH@
312 #  define realpath rpl_realpath
313 # endif
314 # if !@HAVE_REALPATH@ || @REPLACE_REALPATH@
315 extern char *realpath (const char *name, char *resolved);
316 # endif
317 #elif defined GNULIB_POSIXCHECK
318 # undef realpath
319 # define realpath(n,r)                        \
320     (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \
321                       "canonicalize or canonicalize-lgpl for portability"), \
322      realpath (n, r))
323 #endif
324
325 #if @GNULIB_RPMATCH@
326 # if !@HAVE_RPMATCH@
327 /* Test a user response to a question.
328    Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear.  */
329 extern int rpmatch (const char *response);
330 # endif
331 #elif defined GNULIB_POSIXCHECK
332 # undef rpmatch
333 # define rpmatch(r) \
334     (GL_LINK_WARNING ("rpmatch is unportable - " \
335                       "use gnulib module rpmatch for portability"), \
336      rpmatch (r))
337 #endif
338
339 #if @GNULIB_SETENV@
340 # if !@HAVE_SETENV@
341 /* Set NAME to VALUE in the environment.
342    If REPLACE is nonzero, overwrite an existing value.  */
343 extern int setenv (const char *name, const char *value, int replace);
344 # endif
345 #endif
346
347 #if @GNULIB_STRTOD@
348 # if @REPLACE_STRTOD@
349 #  define strtod rpl_strtod
350 # endif
351 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
352  /* Parse a double from STRING, updating ENDP if appropriate.  */
353 extern double strtod (const char *str, char **endp);
354 # endif
355 #elif defined GNULIB_POSIXCHECK
356 # undef strtod
357 # define strtod(s, e)                           \
358     (GL_LINK_WARNING ("strtod is unportable - " \
359                       "use gnulib module strtod for portability"), \
360      strtod (s, e))
361 #endif
362
363 #if @GNULIB_STRTOLL@
364 # if !@HAVE_STRTOLL@
365 /* Parse a signed integer whose textual representation starts at STRING.
366    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
367    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
368    "0x").
369    If ENDPTR is not NULL, the address of the first byte after the integer is
370    stored in *ENDPTR.
371    Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
372    to ERANGE.  */
373 extern long long strtoll (const char *string, char **endptr, int base);
374 # endif
375 #elif defined GNULIB_POSIXCHECK
376 # undef strtoll
377 # define strtoll(s,e,b) \
378     (GL_LINK_WARNING ("strtoll is unportable - " \
379                       "use gnulib module strtoll for portability"), \
380      strtoll (s, e, b))
381 #endif
382
383 #if @GNULIB_STRTOULL@
384 # if !@HAVE_STRTOULL@
385 /* Parse an unsigned integer whose textual representation starts at STRING.
386    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
387    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
388    "0x").
389    If ENDPTR is not NULL, the address of the first byte after the integer is
390    stored in *ENDPTR.
391    Upon overflow, the return value is ULLONG_MAX, and errno is set to
392    ERANGE.  */
393 extern unsigned long long strtoull (const char *string, char **endptr, int base);
394 # endif
395 #elif defined GNULIB_POSIXCHECK
396 # undef strtoull
397 # define strtoull(s,e,b) \
398     (GL_LINK_WARNING ("strtoull is unportable - " \
399                       "use gnulib module strtoull for portability"), \
400      strtoull (s, e, b))
401 #endif
402
403 #if @GNULIB_UNSETENV@
404 # if @HAVE_UNSETENV@
405 #  if @VOID_UNSETENV@
406 /* On some systems, unsetenv() returns void.
407    This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4.  */
408 #   define unsetenv(name) ((unsetenv)(name), 0)
409 #  endif
410 # else
411 /* Remove the variable NAME from the environment.  */
412 extern int unsetenv (const char *name);
413 # endif
414 #endif
415
416 #ifdef __cplusplus
417 }
418 #endif
419
420 #endif /* _GL_STDLIB_H */
421 #endif /* _GL_STDLIB_H */
422 #endif