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