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