Use stdint.h, for int32_t.
[gnulib.git] / lib / stdlib.in.h
1 /* A GNU-like <stdlib.h>.
2
3    Copyright (C) 1995, 2001-2004, 2006-2008 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
39 /* Solaris declares getloadavg() in <sys/loadavg.h>.  */
40 #if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
41 # include <sys/loadavg.h>
42 #endif
43
44 #if @GNULIB_RANDOM_R@
45 # include <stdint.h>
46 #endif
47
48 /* The definition of GL_LINK_WARNING is copied here.  */
49
50
51 /* Some systems do not define EXIT_*, despite otherwise supporting C89.  */
52 #ifndef EXIT_SUCCESS
53 # define EXIT_SUCCESS 0
54 #endif
55 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
56    with proper operation of xargs.  */
57 #ifndef EXIT_FAILURE
58 # define EXIT_FAILURE 1
59 #elif EXIT_FAILURE != 1
60 # undef EXIT_FAILURE
61 # define EXIT_FAILURE 1
62 #endif
63
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69
70 #if @GNULIB_MALLOC_POSIX@
71 # if !@HAVE_MALLOC_POSIX@
72 #  undef malloc
73 #  define malloc rpl_malloc
74 extern void * malloc (size_t size);
75 # endif
76 #elif defined GNULIB_POSIXCHECK
77 # undef malloc
78 # define malloc(s) \
79     (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
80                       "use gnulib module malloc-posix for portability"), \
81      malloc (s))
82 #endif
83
84
85 #if @GNULIB_REALLOC_POSIX@
86 # if !@HAVE_REALLOC_POSIX@
87 #  undef realloc
88 #  define realloc rpl_realloc
89 extern void * realloc (void *ptr, size_t size);
90 # endif
91 #elif defined GNULIB_POSIXCHECK
92 # undef realloc
93 # define realloc(p,s) \
94     (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
95                       "use gnulib module realloc-posix for portability"), \
96      realloc (p, s))
97 #endif
98
99
100 #if @GNULIB_CALLOC_POSIX@
101 # if !@HAVE_CALLOC_POSIX@
102 #  undef calloc
103 #  define calloc rpl_calloc
104 extern void * calloc (size_t nmemb, size_t size);
105 # endif
106 #elif defined GNULIB_POSIXCHECK
107 # undef calloc
108 # define calloc(n,s) \
109     (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
110                       "use gnulib module calloc-posix for portability"), \
111      calloc (n, s))
112 #endif
113
114
115 #if @GNULIB_ATOLL@
116 # if !@HAVE_ATOLL@
117 /* Parse a signed decimal integer.
118    Returns the value of the integer.  Errors are not detected.  */
119 extern long long atoll (const char *string);
120 # endif
121 #elif defined GNULIB_POSIXCHECK
122 # undef atoll
123 # define atoll(s) \
124     (GL_LINK_WARNING ("atoll is unportable - " \
125                       "use gnulib module atoll for portability"), \
126      atoll (s))
127 #endif
128
129
130 #if @GNULIB_GETLOADAVG@
131 # if !@HAVE_DECL_GETLOADAVG@
132 /* Store max(NELEM,3) load average numbers in LOADAVG[].
133    The three numbers are the load average of the last 1 minute, the last 5
134    minutes, and the last 15 minutes, respectively.
135    LOADAVG is an array of NELEM numbers.  */
136 extern int getloadavg (double loadavg[], int nelem);
137 # endif
138 #elif defined GNULIB_POSIXCHECK
139 # undef getloadavg
140 # define getloadavg(l,n) \
141     (GL_LINK_WARNING ("getloadavg is not portable - " \
142                       "use gnulib module getloadavg for portability"), \
143      getloadavg (l, n))
144 #endif
145
146
147 #if @GNULIB_GETSUBOPT@
148 /* Assuming *OPTIONP is a comma separated list of elements of the form
149    "token" or "token=value", getsubopt parses the first of these elements.
150    If the first element refers to a "token" that is member of the given
151    NULL-terminated array of tokens:
152      - It replaces the comma with a NUL byte, updates *OPTIONP to point past
153        the first option and the comma, sets *VALUEP to the value of the
154        element (or NULL if it doesn't contain an "=" sign),
155      - It returns the index of the "token" in the given array of tokens.
156    Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
157    For more details see the POSIX:2001 specification.
158    http://www.opengroup.org/susv3xsh/getsubopt.html */
159 # if !@HAVE_GETSUBOPT@
160 extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
161 # endif
162 #elif defined GNULIB_POSIXCHECK
163 # undef getsubopt
164 # define getsubopt(o,t,v) \
165     (GL_LINK_WARNING ("getsubopt is unportable - " \
166                       "use gnulib module getsubopt for portability"), \
167      getsubopt (o, t, v))
168 #endif
169
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
189 #if @GNULIB_MKSTEMP@
190 # if @REPLACE_MKSTEMP@
191 /* Create a unique temporary file from TEMPLATE.
192    The last six characters of TEMPLATE must be "XXXXXX";
193    they are replaced with a string that makes the file name unique.
194    The file is then created, ensuring it didn't exist before.
195    The file is created read-write (mask at least 0600 & ~umask), but it may be
196    world-readable and world-writable (mask 0666 & ~umask), depending on the
197    implementation.
198    Returns the open file descriptor if successful, otherwise -1 and errno
199    set.  */
200 #  define mkstemp rpl_mkstemp
201 extern int mkstemp (char * /*template*/);
202 # else
203 /* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
204 #  include <unistd.h>
205 # endif
206 #elif defined GNULIB_POSIXCHECK
207 # undef mkstemp
208 # define mkstemp(t) \
209     (GL_LINK_WARNING ("mkstemp is unportable - " \
210                       "use gnulib module mkstemp for portability"), \
211      mkstemp (t))
212 #endif
213
214
215 #if @GNULIB_PUTENV@
216 # if @REPLACE_PUTENV@
217 #  undef putenv
218 #  define putenv rpl_putenv
219 extern int putenv (char *string);
220 # endif
221 #endif
222
223
224 #if @GNULIB_RANDOM_R@
225 # if !@HAVE_RANDOM_R@
226
227 #  ifndef RAND_MAX
228 #   define RAND_MAX 2147483647
229 #  endif
230
231 int srandom_r (unsigned int seed, struct random_data *rand_state);
232 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
233                  struct random_data *rand_state);
234 int setstate_r (char *arg_state, struct random_data *rand_state);
235 int random_r (struct random_data *buf, int32_t *result);
236 # endif
237 #elif defined GNULIB_POSIXCHECK
238 # undef random_r
239 # define random_r(b,r)                            \
240     (GL_LINK_WARNING ("random_r is unportable - " \
241                       "use gnulib module random_r for portability"), \
242      random_r (b,r))
243 # undef initstate_r
244 # define initstate_r(s,b,sz,r)                       \
245     (GL_LINK_WARNING ("initstate_r is unportable - " \
246                       "use gnulib module random_r for portability"), \
247      initstate_r (s,b,sz,r))
248 # undef srandom_r
249 # define srandom_r(s,r)                            \
250     (GL_LINK_WARNING ("srandom_r is unportable - " \
251                       "use gnulib module random_r for portability"), \
252      srandom_r (s,r))
253 # undef setstate_r
254 # define setstate_r(a,r)                                    \
255     (GL_LINK_WARNING ("setstate_r is unportable - " \
256                       "use gnulib module random_r for portability"), \
257      setstate_r (a,r))
258 #endif
259
260
261 #if @GNULIB_RPMATCH@
262 # if !@HAVE_RPMATCH@
263 /* Test a user response to a question.
264    Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear.  */
265 extern int rpmatch (const char *response);
266 # endif
267 #elif defined GNULIB_POSIXCHECK
268 # undef rpmatch
269 # define rpmatch(r) \
270     (GL_LINK_WARNING ("rpmatch is unportable - " \
271                       "use gnulib module rpmatch for portability"), \
272      rpmatch (r))
273 #endif
274
275
276 #if @GNULIB_SETENV@
277 # if !@HAVE_SETENV@
278 /* Set NAME to VALUE in the environment.
279    If REPLACE is nonzero, overwrite an existing value.  */
280 extern int setenv (const char *name, const char *value, int replace);
281 # endif
282 #endif
283
284
285 #if @GNULIB_UNSETENV@
286 # if @HAVE_UNSETENV@
287 #  if @VOID_UNSETENV@
288 /* On some systems, unsetenv() returns void.
289    This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4.  */
290 #   define unsetenv(name) ((unsetenv)(name), 0)
291 #  endif
292 # else
293 /* Remove the variable NAME from the environment.  */
294 extern int unsetenv (const char *name);
295 # endif
296 #endif
297
298
299 #if @GNULIB_STRTOD@
300 # if @REPLACE_STRTOD@
301 #  define strtod rpl_strtod
302 # endif
303 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
304  /* Parse a double from STRING, updating ENDP if appropriate.  */
305 extern double strtod (const char *str, char **endp);
306 # endif
307 #elif defined GNULIB_POSIXCHECK
308 # undef strtod
309 # define strtod(s, e)                           \
310     (GL_LINK_WARNING ("strtod is unportable - " \
311                       "use gnulib module strtod for portability"), \
312      strtod (s, e))
313 #endif
314
315
316 #if @GNULIB_STRTOLL@
317 # if !@HAVE_STRTOLL@
318 /* Parse a signed integer whose textual representation starts at STRING.
319    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
320    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
321    "0x").
322    If ENDPTR is not NULL, the address of the first byte after the integer is
323    stored in *ENDPTR.
324    Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
325    to ERANGE.  */
326 extern long long strtoll (const char *string, char **endptr, int base);
327 # endif
328 #elif defined GNULIB_POSIXCHECK
329 # undef strtoll
330 # define strtoll(s,e,b) \
331     (GL_LINK_WARNING ("strtoll is unportable - " \
332                       "use gnulib module strtoll for portability"), \
333      strtoll (s, e, b))
334 #endif
335
336
337 #if @GNULIB_STRTOULL@
338 # if !@HAVE_STRTOULL@
339 /* Parse an unsigned integer whose textual representation starts at STRING.
340    The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
341    it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
342    "0x").
343    If ENDPTR is not NULL, the address of the first byte after the integer is
344    stored in *ENDPTR.
345    Upon overflow, the return value is ULLONG_MAX, and errno is set to
346    ERANGE.  */
347 extern unsigned long long strtoull (const char *string, char **endptr, int base);
348 # endif
349 #elif defined GNULIB_POSIXCHECK
350 # undef strtoull
351 # define strtoull(s,e,b) \
352     (GL_LINK_WARNING ("strtoull is unportable - " \
353                       "use gnulib module strtoull for portability"), \
354      strtoull (s, e, b))
355 #endif
356
357
358 #ifdef __cplusplus
359 }
360 #endif
361
362 #endif /* _GL_STDLIB_H */
363 #endif /* _GL_STDLIB_H */
364 #endif