stdlib: sort witness names
[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@ && @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_GETLOADAVG@
119 # if !@HAVE_DECL_GETLOADAVG@
120 /* Store max(NELEM,3) load average numbers in LOADAVG[].
121    The three numbers are the load average of the last 1 minute, the last 5
122    minutes, and the last 15 minutes, respectively.
123    LOADAVG is an array of NELEM numbers.  */
124 extern int getloadavg (double loadavg[], int nelem);
125 # endif
126 #elif defined GNULIB_POSIXCHECK
127 # undef getloadavg
128 # define getloadavg(l,n) \
129     (GL_LINK_WARNING ("getloadavg is not portable - " \
130                       "use gnulib module getloadavg for portability"), \
131      getloadavg (l, n))
132 #endif
133
134 #if @GNULIB_GETSUBOPT@
135 /* Assuming *OPTIONP is a comma separated list of elements of the form
136    "token" or "token=value", getsubopt parses the first of these elements.
137    If the first element refers to a "token" that is member of the given
138    NULL-terminated array of tokens:
139      - It replaces the comma with a NUL byte, updates *OPTIONP to point past
140        the first option and the comma, sets *VALUEP to the value of the
141        element (or NULL if it doesn't contain an "=" sign),
142      - It returns the index of the "token" in the given array of tokens.
143    Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
144    For more details see the POSIX:2001 specification.
145    http://www.opengroup.org/susv3xsh/getsubopt.html */
146 # if !@HAVE_GETSUBOPT@
147 extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
148 # endif
149 #elif defined GNULIB_POSIXCHECK
150 # undef getsubopt
151 # define getsubopt(o,t,v) \
152     (GL_LINK_WARNING ("getsubopt is unportable - " \
153                       "use gnulib module getsubopt for portability"), \
154      getsubopt (o, t, v))
155 #endif
156
157 #if @GNULIB_MALLOC_POSIX@
158 # if !@HAVE_MALLOC_POSIX@
159 #  undef malloc
160 #  define malloc rpl_malloc
161 extern void * malloc (size_t size);
162 # endif
163 #elif defined GNULIB_POSIXCHECK
164 # undef malloc
165 # define malloc(s) \
166     (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
167                       "use gnulib module malloc-posix for portability"), \
168      malloc (s))
169 #endif
170
171 #if @GNULIB_MKDTEMP@
172 # if !@HAVE_MKDTEMP@
173 /* Create a unique temporary directory from TEMPLATE.
174    The last six characters of TEMPLATE must be "XXXXXX";
175    they are replaced with a string that makes the directory name unique.
176    Returns TEMPLATE, or a null pointer if it cannot get a unique name.
177    The directory is created mode 700.  */
178 extern char * mkdtemp (char * /*template*/);
179 # endif
180 #elif defined GNULIB_POSIXCHECK
181 # undef mkdtemp
182 # define mkdtemp(t) \
183     (GL_LINK_WARNING ("mkdtemp is unportable - " \
184                       "use gnulib module mkdtemp for portability"), \
185      mkdtemp (t))
186 #endif
187
188 #if @GNULIB_MKOSTEMP@
189 # if !@HAVE_MKOSTEMP@
190 /* Create a unique temporary file from TEMPLATE.
191    The last six characters of TEMPLATE must be "XXXXXX";
192    they are replaced with a string that makes the file name unique.
193    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
194    and O_TEXT, O_BINARY (defined in "binary-io.h").
195    The file is then created, with the specified flags, ensuring it didn't exist
196    before.
197    The file is created read-write (mask at least 0600 & ~umask), but it may be
198    world-readable and world-writable (mask 0666 & ~umask), depending on the
199    implementation.
200    Returns the open file descriptor if successful, otherwise -1 and errno
201    set.  */
202 extern int mkostemp (char * /*template*/, int /*flags*/);
203 # endif
204 #elif defined GNULIB_POSIXCHECK
205 # undef mkostemp
206 # define mkostemp(t,f) \
207     (GL_LINK_WARNING ("mkostemp is unportable - " \
208                       "use gnulib module mkostemp for portability"), \
209      mkostemp (t, f))
210 #endif
211
212 #if @GNULIB_MKSTEMP@
213 # if @REPLACE_MKSTEMP@
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 file is then created, ensuring it didn't exist before.
218    The file is created read-write (mask at least 0600 & ~umask), but it may be
219    world-readable and world-writable (mask 0666 & ~umask), depending on the
220    implementation.
221    Returns the open file descriptor if successful, otherwise -1 and errno
222    set.  */
223 #  define mkstemp rpl_mkstemp
224 extern int mkstemp (char * /*template*/);
225 # else
226 /* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
227 #  include <unistd.h>
228 # endif
229 #elif defined GNULIB_POSIXCHECK
230 # undef mkstemp
231 # define mkstemp(t) \
232     (GL_LINK_WARNING ("mkstemp is unportable - " \
233                       "use gnulib module mkstemp for portability"), \
234      mkstemp (t))
235 #endif
236
237 #if @GNULIB_PUTENV@
238 # if @REPLACE_PUTENV@
239 #  undef putenv
240 #  define putenv rpl_putenv
241 extern int putenv (char *string);
242 # endif
243 #endif
244
245 #if @GNULIB_RANDOM_R@
246 # if !@HAVE_RANDOM_R@
247
248 #  ifndef RAND_MAX
249 #   define RAND_MAX 2147483647
250 #  endif
251
252 int srandom_r (unsigned int seed, struct random_data *rand_state);
253 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
254                  struct random_data *rand_state);
255 int setstate_r (char *arg_state, struct random_data *rand_state);
256 int random_r (struct random_data *buf, int32_t *result);
257 # endif
258 #elif defined GNULIB_POSIXCHECK
259 # undef random_r
260 # define random_r(b,r)                            \
261     (GL_LINK_WARNING ("random_r is unportable - " \
262                       "use gnulib module random_r for portability"), \
263      random_r (b,r))
264 # undef initstate_r
265 # define initstate_r(s,b,sz,r)                       \
266     (GL_LINK_WARNING ("initstate_r is unportable - " \
267                       "use gnulib module random_r for portability"), \
268      initstate_r (s,b,sz,r))
269 # undef srandom_r
270 # define srandom_r(s,r)                            \
271     (GL_LINK_WARNING ("srandom_r is unportable - " \
272                       "use gnulib module random_r for portability"), \
273      srandom_r (s,r))
274 # undef setstate_r
275 # define setstate_r(a,r)                                    \
276     (GL_LINK_WARNING ("setstate_r is unportable - " \
277                       "use gnulib module random_r for portability"), \
278      setstate_r (a,r))
279 #endif
280
281 #if @GNULIB_REALLOC_POSIX@
282 # if !@HAVE_REALLOC_POSIX@
283 #  undef realloc
284 #  define realloc rpl_realloc
285 extern void * realloc (void *ptr, size_t size);
286 # endif
287 #elif defined GNULIB_POSIXCHECK
288 # undef realloc
289 # define realloc(p,s) \
290     (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
291                       "use gnulib module realloc-posix for portability"), \
292      realloc (p, s))
293 #endif
294
295 #if @GNULIB_RPMATCH@
296 # if !@HAVE_RPMATCH@
297 /* Test a user response to a question.
298    Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear.  */
299 extern int rpmatch (const char *response);
300 # endif
301 #elif defined GNULIB_POSIXCHECK
302 # undef rpmatch
303 # define rpmatch(r) \
304     (GL_LINK_WARNING ("rpmatch is unportable - " \
305                       "use gnulib module rpmatch for portability"), \
306      rpmatch (r))
307 #endif
308
309 #if @GNULIB_SETENV@
310 # if !@HAVE_SETENV@
311 /* Set NAME to VALUE in the environment.
312    If REPLACE is nonzero, overwrite an existing value.  */
313 extern int setenv (const char *name, const char *value, int replace);
314 # endif
315 #endif
316
317 #if @GNULIB_STRTOD@
318 # if @REPLACE_STRTOD@
319 #  define strtod rpl_strtod
320 # endif
321 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
322  /* Parse a double from STRING, updating ENDP if appropriate.  */
323 extern double strtod (const char *str, char **endp);
324 # endif
325 #elif defined GNULIB_POSIXCHECK
326 # undef strtod
327 # define strtod(s, e)                           \
328     (GL_LINK_WARNING ("strtod is unportable - " \
329                       "use gnulib module strtod for portability"), \
330      strtod (s, e))
331 #endif
332
333 #if @GNULIB_STRTOLL@
334 # if !@HAVE_STRTOLL@
335 /* Parse a signed integer whose textual representation starts at STRING.
336    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
337    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
338    "0x").
339    If ENDPTR is not NULL, the address of the first byte after the integer is
340    stored in *ENDPTR.
341    Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
342    to ERANGE.  */
343 extern long long strtoll (const char *string, char **endptr, int base);
344 # endif
345 #elif defined GNULIB_POSIXCHECK
346 # undef strtoll
347 # define strtoll(s,e,b) \
348     (GL_LINK_WARNING ("strtoll is unportable - " \
349                       "use gnulib module strtoll for portability"), \
350      strtoll (s, e, b))
351 #endif
352
353 #if @GNULIB_STRTOULL@
354 # if !@HAVE_STRTOULL@
355 /* Parse an unsigned integer whose textual representation starts at STRING.
356    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
357    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
358    "0x").
359    If ENDPTR is not NULL, the address of the first byte after the integer is
360    stored in *ENDPTR.
361    Upon overflow, the return value is ULLONG_MAX, and errno is set to
362    ERANGE.  */
363 extern unsigned long long strtoull (const char *string, char **endptr, int base);
364 # endif
365 #elif defined GNULIB_POSIXCHECK
366 # undef strtoull
367 # define strtoull(s,e,b) \
368     (GL_LINK_WARNING ("strtoull is unportable - " \
369                       "use gnulib module strtoull for portability"), \
370      strtoull (s, e, b))
371 #endif
372
373 #if @GNULIB_UNSETENV@
374 # if @HAVE_UNSETENV@
375 #  if @VOID_UNSETENV@
376 /* On some systems, unsetenv() returns void.
377    This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4.  */
378 #   define unsetenv(name) ((unsetenv)(name), 0)
379 #  endif
380 # else
381 /* Remove the variable NAME from the environment.  */
382 extern int unsetenv (const char *name);
383 # endif
384 #endif
385
386 #ifdef __cplusplus
387 }
388 #endif
389
390 #endif /* _GL_STDLIB_H */
391 #endif /* _GL_STDLIB_H */
392 #endif