1 /* A GNU-like <stdlib.h>.
3 Copyright (C) 1995, 2001-2004, 2006-2019 Free Software Foundation, Inc.
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_system_stdlib_h || defined __need_malloc_and_calloc
24 /* Special invocation conventions inside some gnulib header files,
25 and inside some glibc header files, respectively. */
27 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
30 /* Normal invocation convention. */
32 #ifndef _@GUARD_PREFIX@_STDLIB_H
34 /* The include_next requires a split double-inclusion guard. */
35 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
37 #ifndef _@GUARD_PREFIX@_STDLIB_H
38 #define _@GUARD_PREFIX@_STDLIB_H
40 /* NetBSD 5.0 mis-defines NULL. */
43 /* MirBSD 10 defines WEXITSTATUS in <sys/wait.h>, not in <stdlib.h>. */
44 #if @GNULIB_SYSTEM_POSIX@ && !defined WEXITSTATUS
45 # include <sys/wait.h>
48 /* Solaris declares getloadavg() in <sys/loadavg.h>. */
49 #if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
50 /* OpenIndiana has a bug: <sys/time.h> must be included before
52 # include <sys/time.h>
53 # include <sys/loadavg.h>
56 /* Native Windows platforms declare mktemp() in <io.h>. */
57 #if 0 && (defined _WIN32 && ! defined __CYGWIN__)
63 /* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
64 from <stdlib.h> if _REENTRANT is defined. Include it whenever we need
65 'struct random_data'. */
70 # if !@HAVE_STRUCT_RANDOM_DATA@ || @REPLACE_RANDOM_R@ || !@HAVE_RANDOM_R@
74 # if !@HAVE_STRUCT_RANDOM_DATA@
75 /* Define 'struct random_data'.
76 But allow multiple gnulib generated <stdlib.h> replacements to coexist. */
77 # if !GNULIB_defined_struct_random_data
80 int32_t *fptr
; /* Front pointer. */
81 int32_t *rptr
; /* Rear pointer. */
82 int32_t *state
; /* Array of state values. */
83 int rand_type
; /* Type of random number generator. */
84 int rand_deg
; /* Degree of random number generator. */
85 int rand_sep
; /* Distance between front and rear. */
86 int32_t *end_ptr
; /* Pointer behind state table. */
88 # define GNULIB_defined_struct_random_data 1
93 #if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !(defined _WIN32 && ! defined __CYGWIN__)
94 /* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
95 /* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
96 /* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
97 /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
98 /* But avoid namespace pollution on glibc systems and native Windows. */
102 /* The __attribute__ feature is available in gcc versions 2.5 and later.
103 The attribute __pure__ was added in gcc 2.96. */
104 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
105 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
107 # define _GL_ATTRIBUTE_PURE /* empty */
110 /* The definition of _Noreturn is copied here. */
112 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
114 /* The definition of _GL_ARG_NONNULL is copied here. */
116 /* The definition of _GL_WARN_ON_USE is copied here. */
119 /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
121 # define EXIT_SUCCESS 0
123 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
124 with proper operation of xargs. */
126 # define EXIT_FAILURE 1
127 #elif EXIT_FAILURE != 1
129 # define EXIT_FAILURE 1
134 /* Terminate the current process with the given return code, without running
135 the 'atexit' handlers. */
137 _GL_FUNCDECL_SYS (_Exit
, _Noreturn
void, (int status
));
139 _GL_CXXALIAS_SYS (_Exit
, void, (int status
));
140 _GL_CXXALIASWARN (_Exit
);
141 #elif defined GNULIB_POSIXCHECK
143 # if HAVE_RAW_DECL__EXIT
144 _GL_WARN_ON_USE (_Exit
, "_Exit is unportable - "
145 "use gnulib module _Exit for portability");
151 /* Parse a signed decimal integer.
152 Returns the value of the integer. Errors are not detected. */
154 _GL_FUNCDECL_SYS (atoll
, long long, (const char *string
)
156 _GL_ARG_NONNULL ((1)));
158 _GL_CXXALIAS_SYS (atoll
, long long, (const char *string
));
159 _GL_CXXALIASWARN (atoll
);
160 #elif defined GNULIB_POSIXCHECK
162 # if HAVE_RAW_DECL_ATOLL
163 _GL_WARN_ON_USE (atoll
, "atoll is unportable - "
164 "use gnulib module atoll for portability");
168 #if @GNULIB_CALLOC_POSIX@
169 # if @REPLACE_CALLOC@
170 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
172 # define calloc rpl_calloc
174 _GL_FUNCDECL_RPL (calloc
, void *, (size_t nmemb
, size_t size
));
175 _GL_CXXALIAS_RPL (calloc
, void *, (size_t nmemb
, size_t size
));
177 _GL_CXXALIAS_SYS (calloc
, void *, (size_t nmemb
, size_t size
));
179 _GL_CXXALIASWARN (calloc
);
180 #elif defined GNULIB_POSIXCHECK
182 /* Assume calloc is always declared. */
183 _GL_WARN_ON_USE (calloc
, "calloc is not POSIX compliant everywhere - "
184 "use gnulib module calloc-posix for portability");
187 #if @GNULIB_CANONICALIZE_FILE_NAME@
188 # if @REPLACE_CANONICALIZE_FILE_NAME@
189 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
190 # define canonicalize_file_name rpl_canonicalize_file_name
192 _GL_FUNCDECL_RPL (canonicalize_file_name
, char *, (const char *name
)
193 _GL_ARG_NONNULL ((1)));
194 _GL_CXXALIAS_RPL (canonicalize_file_name
, char *, (const char *name
));
196 # if !@HAVE_CANONICALIZE_FILE_NAME@
197 _GL_FUNCDECL_SYS (canonicalize_file_name
, char *, (const char *name
)
198 _GL_ARG_NONNULL ((1)));
200 _GL_CXXALIAS_SYS (canonicalize_file_name
, char *, (const char *name
));
202 _GL_CXXALIASWARN (canonicalize_file_name
);
203 #elif defined GNULIB_POSIXCHECK
204 # undef canonicalize_file_name
205 # if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
206 _GL_WARN_ON_USE (canonicalize_file_name
,
207 "canonicalize_file_name is unportable - "
208 "use gnulib module canonicalize-lgpl for portability");
212 #if @GNULIB_GETLOADAVG@
213 /* Store max(NELEM,3) load average numbers in LOADAVG[].
214 The three numbers are the load average of the last 1 minute, the last 5
215 minutes, and the last 15 minutes, respectively.
216 LOADAVG is an array of NELEM numbers. */
217 # if !@HAVE_DECL_GETLOADAVG@
218 _GL_FUNCDECL_SYS (getloadavg
, int, (double loadavg
[], int nelem
)
219 _GL_ARG_NONNULL ((1)));
221 _GL_CXXALIAS_SYS (getloadavg
, int, (double loadavg
[], int nelem
));
222 _GL_CXXALIASWARN (getloadavg
);
223 #elif defined GNULIB_POSIXCHECK
225 # if HAVE_RAW_DECL_GETLOADAVG
226 _GL_WARN_ON_USE (getloadavg
, "getloadavg is not portable - "
227 "use gnulib module getloadavg for portability");
231 #if @GNULIB_GETSUBOPT@
232 /* Assuming *OPTIONP is a comma separated list of elements of the form
233 "token" or "token=value", getsubopt parses the first of these elements.
234 If the first element refers to a "token" that is member of the given
235 NULL-terminated array of tokens:
236 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
237 the first option and the comma, sets *VALUEP to the value of the
238 element (or NULL if it doesn't contain an "=" sign),
239 - It returns the index of the "token" in the given array of tokens.
240 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
241 For more details see the POSIX:2001 specification.
242 http://www.opengroup.org/susv3xsh/getsubopt.html */
243 # if !@HAVE_GETSUBOPT@
244 _GL_FUNCDECL_SYS (getsubopt
, int,
245 (char **optionp
, char *const *tokens
, char **valuep
)
246 _GL_ARG_NONNULL ((1, 2, 3)));
248 _GL_CXXALIAS_SYS (getsubopt
, int,
249 (char **optionp
, char *const *tokens
, char **valuep
));
250 _GL_CXXALIASWARN (getsubopt
);
251 #elif defined GNULIB_POSIXCHECK
253 # if HAVE_RAW_DECL_GETSUBOPT
254 _GL_WARN_ON_USE (getsubopt
, "getsubopt is unportable - "
255 "use gnulib module getsubopt for portability");
260 /* Change the ownership and access permission of the slave side of the
261 pseudo-terminal whose master side is specified by FD. */
263 _GL_FUNCDECL_SYS (grantpt
, int, (int fd
));
265 _GL_CXXALIAS_SYS (grantpt
, int, (int fd
));
266 _GL_CXXALIASWARN (grantpt
);
267 #elif defined GNULIB_POSIXCHECK
269 # if HAVE_RAW_DECL_GRANTPT
270 _GL_WARN_ON_USE (grantpt
, "grantpt is not portable - "
271 "use gnulib module grantpt for portability");
275 /* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
276 rely on GNU or POSIX semantics for malloc and realloc (for example,
277 by never specifying a zero size), so it does not need malloc or
278 realloc to be redefined. */
279 #if @GNULIB_MALLOC_POSIX@
280 # if @REPLACE_MALLOC@
281 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
282 || _GL_USE_STDLIB_ALLOC)
284 # define malloc rpl_malloc
286 _GL_FUNCDECL_RPL (malloc
, void *, (size_t size
));
287 _GL_CXXALIAS_RPL (malloc
, void *, (size_t size
));
289 _GL_CXXALIAS_SYS (malloc
, void *, (size_t size
));
291 _GL_CXXALIASWARN (malloc
);
292 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
294 /* Assume malloc is always declared. */
295 _GL_WARN_ON_USE (malloc
, "malloc is not POSIX compliant everywhere - "
296 "use gnulib module malloc-posix for portability");
299 /* Convert a multibyte character to a wide character. */
301 # if @REPLACE_MBTOWC@
302 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
304 # define mbtowc rpl_mbtowc
306 _GL_FUNCDECL_RPL (mbtowc
, int, (wchar_t *pwc
, const char *s
, size_t n
));
307 _GL_CXXALIAS_RPL (mbtowc
, int, (wchar_t *pwc
, const char *s
, size_t n
));
310 _GL_FUNCDECL_SYS (mbtowc
, int, (wchar_t *pwc
, const char *s
, size_t n
));
312 _GL_CXXALIAS_SYS (mbtowc
, int, (wchar_t *pwc
, const char *s
, size_t n
));
314 _GL_CXXALIASWARN (mbtowc
);
315 #elif defined GNULIB_POSIXCHECK
317 # if HAVE_RAW_DECL_MBTOWC
318 _GL_WARN_ON_USE (mbtowc
, "mbtowc is not portable - "
319 "use gnulib module mbtowc for portability");
324 /* Create a unique temporary directory from TEMPLATE.
325 The last six characters of TEMPLATE must be "XXXXXX";
326 they are replaced with a string that makes the directory name unique.
327 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
328 The directory is created mode 700. */
330 _GL_FUNCDECL_SYS (mkdtemp
, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
332 _GL_CXXALIAS_SYS (mkdtemp
, char *, (char * /*template*/));
333 _GL_CXXALIASWARN (mkdtemp
);
334 #elif defined GNULIB_POSIXCHECK
336 # if HAVE_RAW_DECL_MKDTEMP
337 _GL_WARN_ON_USE (mkdtemp
, "mkdtemp is unportable - "
338 "use gnulib module mkdtemp for portability");
342 #if @GNULIB_MKOSTEMP@
343 /* Create a unique temporary file from TEMPLATE.
344 The last six characters of TEMPLATE must be "XXXXXX";
345 they are replaced with a string that makes the file name unique.
346 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
347 and O_TEXT, O_BINARY (defined in "binary-io.h").
348 The file is then created, with the specified flags, ensuring it didn't exist
350 The file is created read-write (mask at least 0600 & ~umask), but it may be
351 world-readable and world-writable (mask 0666 & ~umask), depending on the
353 Returns the open file descriptor if successful, otherwise -1 and errno
355 # if !@HAVE_MKOSTEMP@
356 _GL_FUNCDECL_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/)
357 _GL_ARG_NONNULL ((1)));
359 _GL_CXXALIAS_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/));
360 _GL_CXXALIASWARN (mkostemp
);
361 #elif defined GNULIB_POSIXCHECK
363 # if HAVE_RAW_DECL_MKOSTEMP
364 _GL_WARN_ON_USE (mkostemp
, "mkostemp is unportable - "
365 "use gnulib module mkostemp for portability");
369 #if @GNULIB_MKOSTEMPS@
370 /* Create a unique temporary file from TEMPLATE.
371 The last six characters of TEMPLATE before a suffix of length
372 SUFFIXLEN must be "XXXXXX";
373 they are replaced with a string that makes the file name unique.
374 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
375 and O_TEXT, O_BINARY (defined in "binary-io.h").
376 The file is then created, with the specified flags, ensuring it didn't exist
378 The file is created read-write (mask at least 0600 & ~umask), but it may be
379 world-readable and world-writable (mask 0666 & ~umask), depending on the
381 Returns the open file descriptor if successful, otherwise -1 and errno
383 # if !@HAVE_MKOSTEMPS@
384 _GL_FUNCDECL_SYS (mkostemps
, int,
385 (char * /*template*/, int /*suffixlen*/, int /*flags*/)
386 _GL_ARG_NONNULL ((1)));
388 _GL_CXXALIAS_SYS (mkostemps
, int,
389 (char * /*template*/, int /*suffixlen*/, int /*flags*/));
390 _GL_CXXALIASWARN (mkostemps
);
391 #elif defined GNULIB_POSIXCHECK
393 # if HAVE_RAW_DECL_MKOSTEMPS
394 _GL_WARN_ON_USE (mkostemps
, "mkostemps is unportable - "
395 "use gnulib module mkostemps for portability");
400 /* Create a unique temporary file from TEMPLATE.
401 The last six characters of TEMPLATE must be "XXXXXX";
402 they are replaced with a string that makes the file name unique.
403 The file is then created, ensuring it didn't exist before.
404 The file is created read-write (mask at least 0600 & ~umask), but it may be
405 world-readable and world-writable (mask 0666 & ~umask), depending on the
407 Returns the open file descriptor if successful, otherwise -1 and errno
409 # if @REPLACE_MKSTEMP@
410 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
411 # define mkstemp rpl_mkstemp
413 _GL_FUNCDECL_RPL (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
414 _GL_CXXALIAS_RPL (mkstemp
, int, (char * /*template*/));
416 # if ! @HAVE_MKSTEMP@
417 _GL_FUNCDECL_SYS (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
419 _GL_CXXALIAS_SYS (mkstemp
, int, (char * /*template*/));
421 _GL_CXXALIASWARN (mkstemp
);
422 #elif defined GNULIB_POSIXCHECK
424 # if HAVE_RAW_DECL_MKSTEMP
425 _GL_WARN_ON_USE (mkstemp
, "mkstemp is unportable - "
426 "use gnulib module mkstemp for portability");
430 #if @GNULIB_MKSTEMPS@
431 /* Create a unique temporary file from TEMPLATE.
432 The last six characters of TEMPLATE prior to a suffix of length
433 SUFFIXLEN must be "XXXXXX";
434 they are replaced with a string that makes the file name unique.
435 The file is then created, ensuring it didn't exist before.
436 The file is created read-write (mask at least 0600 & ~umask), but it may be
437 world-readable and world-writable (mask 0666 & ~umask), depending on the
439 Returns the open file descriptor if successful, otherwise -1 and errno
441 # if !@HAVE_MKSTEMPS@
442 _GL_FUNCDECL_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/)
443 _GL_ARG_NONNULL ((1)));
445 _GL_CXXALIAS_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/));
446 _GL_CXXALIASWARN (mkstemps
);
447 #elif defined GNULIB_POSIXCHECK
449 # if HAVE_RAW_DECL_MKSTEMPS
450 _GL_WARN_ON_USE (mkstemps
, "mkstemps is unportable - "
451 "use gnulib module mkstemps for portability");
455 #if @GNULIB_POSIX_OPENPT@
456 /* Return an FD open to the master side of a pseudo-terminal. Flags should
457 include O_RDWR, and may also include O_NOCTTY. */
458 # if !@HAVE_POSIX_OPENPT@
459 _GL_FUNCDECL_SYS (posix_openpt
, int, (int flags
));
461 _GL_CXXALIAS_SYS (posix_openpt
, int, (int flags
));
462 _GL_CXXALIASWARN (posix_openpt
);
463 #elif defined GNULIB_POSIXCHECK
465 # if HAVE_RAW_DECL_POSIX_OPENPT
466 _GL_WARN_ON_USE (posix_openpt
, "posix_openpt is not portable - "
467 "use gnulib module posix_openpt for portability");
472 /* Return the pathname of the pseudo-terminal slave associated with
473 the master FD is open on, or NULL on errors. */
474 # if @REPLACE_PTSNAME@
475 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
477 # define ptsname rpl_ptsname
479 _GL_FUNCDECL_RPL (ptsname
, char *, (int fd
));
480 _GL_CXXALIAS_RPL (ptsname
, char *, (int fd
));
483 _GL_FUNCDECL_SYS (ptsname
, char *, (int fd
));
485 _GL_CXXALIAS_SYS (ptsname
, char *, (int fd
));
487 _GL_CXXALIASWARN (ptsname
);
488 #elif defined GNULIB_POSIXCHECK
490 # if HAVE_RAW_DECL_PTSNAME
491 _GL_WARN_ON_USE (ptsname
, "ptsname is not portable - "
492 "use gnulib module ptsname for portability");
496 #if @GNULIB_PTSNAME_R@
497 /* Set the pathname of the pseudo-terminal slave associated with
498 the master FD is open on and return 0, or set errno and return
499 non-zero on errors. */
500 # if @REPLACE_PTSNAME_R@
501 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
503 # define ptsname_r rpl_ptsname_r
505 _GL_FUNCDECL_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
506 _GL_CXXALIAS_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
508 # if !@HAVE_PTSNAME_R@
509 _GL_FUNCDECL_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
511 _GL_CXXALIAS_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
513 _GL_CXXALIASWARN (ptsname_r
);
514 #elif defined GNULIB_POSIXCHECK
516 # if HAVE_RAW_DECL_PTSNAME_R
517 _GL_WARN_ON_USE (ptsname_r
, "ptsname_r is not portable - "
518 "use gnulib module ptsname_r for portability");
523 # if @REPLACE_PUTENV@
524 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
526 # define putenv rpl_putenv
528 _GL_FUNCDECL_RPL (putenv
, int, (char *string
) _GL_ARG_NONNULL ((1)));
529 _GL_CXXALIAS_RPL (putenv
, int, (char *string
));
531 _GL_CXXALIAS_SYS (putenv
, int, (char *string
));
533 _GL_CXXALIASWARN (putenv
);
537 /* Sort an array of NMEMB elements, starting at address BASE, each element
538 occupying SIZE bytes, in ascending order according to the comparison
540 # if @REPLACE_QSORT_R@
541 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
543 # define qsort_r rpl_qsort_r
545 _GL_FUNCDECL_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
546 int (*compare
) (void const *, void const *,
548 void *arg
) _GL_ARG_NONNULL ((1, 4)));
549 _GL_CXXALIAS_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
550 int (*compare
) (void const *, void const *,
555 _GL_FUNCDECL_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
556 int (*compare
) (void const *, void const *,
558 void *arg
) _GL_ARG_NONNULL ((1, 4)));
560 _GL_CXXALIAS_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
561 int (*compare
) (void const *, void const *,
565 _GL_CXXALIASWARN (qsort_r
);
566 #elif defined GNULIB_POSIXCHECK
568 # if HAVE_RAW_DECL_QSORT_R
569 _GL_WARN_ON_USE (qsort_r
, "qsort_r is not portable - "
570 "use gnulib module qsort_r for portability");
575 #if @GNULIB_RANDOM_R@
576 # if !@HAVE_RANDOM_R@
578 # define RAND_MAX 2147483647
585 # if @REPLACE_RANDOM@
586 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
588 # define random rpl_random
590 _GL_FUNCDECL_RPL (random
, long, (void));
591 _GL_CXXALIAS_RPL (random
, long, (void));
594 _GL_FUNCDECL_SYS (random
, long, (void));
596 _GL_CXXALIAS_SYS (random
, long, (void));
598 _GL_CXXALIASWARN (random
);
599 #elif defined GNULIB_POSIXCHECK
601 # if HAVE_RAW_DECL_RANDOM
602 _GL_WARN_ON_USE (random
, "random is unportable - "
603 "use gnulib module random for portability");
608 # if @REPLACE_RANDOM@
609 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
611 # define srandom rpl_srandom
613 _GL_FUNCDECL_RPL (srandom
, void, (unsigned int seed
));
614 _GL_CXXALIAS_RPL (srandom
, void, (unsigned int seed
));
617 _GL_FUNCDECL_SYS (srandom
, void, (unsigned int seed
));
619 _GL_CXXALIAS_SYS (srandom
, void, (unsigned int seed
));
621 _GL_CXXALIASWARN (srandom
);
622 #elif defined GNULIB_POSIXCHECK
624 # if HAVE_RAW_DECL_SRANDOM
625 _GL_WARN_ON_USE (srandom
, "srandom is unportable - "
626 "use gnulib module random for portability");
631 # if @REPLACE_INITSTATE@
632 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
634 # define initstate rpl_initstate
636 _GL_FUNCDECL_RPL (initstate
, char *,
637 (unsigned int seed
, char *buf
, size_t buf_size
)
638 _GL_ARG_NONNULL ((2)));
639 _GL_CXXALIAS_RPL (initstate
, char *,
640 (unsigned int seed
, char *buf
, size_t buf_size
));
642 # if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
643 _GL_FUNCDECL_SYS (initstate
, char *,
644 (unsigned int seed
, char *buf
, size_t buf_size
)
645 _GL_ARG_NONNULL ((2)));
647 _GL_CXXALIAS_SYS (initstate
, char *,
648 (unsigned int seed
, char *buf
, size_t buf_size
));
650 _GL_CXXALIASWARN (initstate
);
651 #elif defined GNULIB_POSIXCHECK
653 # if HAVE_RAW_DECL_INITSTATE
654 _GL_WARN_ON_USE (initstate
, "initstate is unportable - "
655 "use gnulib module random for portability");
660 # if @REPLACE_SETSTATE@
661 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
663 # define setstate rpl_setstate
665 _GL_FUNCDECL_RPL (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
666 _GL_CXXALIAS_RPL (setstate
, char *, (char *arg_state
));
668 # if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
669 _GL_FUNCDECL_SYS (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
671 _GL_CXXALIAS_SYS (setstate
, char *, (char *arg_state
));
673 _GL_CXXALIASWARN (setstate
);
674 #elif defined GNULIB_POSIXCHECK
676 # if HAVE_RAW_DECL_SETSTATE
677 _GL_WARN_ON_USE (setstate
, "setstate is unportable - "
678 "use gnulib module random for portability");
683 #if @GNULIB_RANDOM_R@
684 # if @REPLACE_RANDOM_R@
685 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # define random_r rpl_random_r
689 _GL_FUNCDECL_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
)
690 _GL_ARG_NONNULL ((1, 2)));
691 _GL_CXXALIAS_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
));
693 # if !@HAVE_RANDOM_R@
694 _GL_FUNCDECL_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
)
695 _GL_ARG_NONNULL ((1, 2)));
697 _GL_CXXALIAS_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
));
699 _GL_CXXALIASWARN (random_r
);
700 #elif defined GNULIB_POSIXCHECK
702 # if HAVE_RAW_DECL_RANDOM_R
703 _GL_WARN_ON_USE (random_r
, "random_r is unportable - "
704 "use gnulib module random_r for portability");
708 #if @GNULIB_RANDOM_R@
709 # if @REPLACE_RANDOM_R@
710 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
712 # define srandom_r rpl_srandom_r
714 _GL_FUNCDECL_RPL (srandom_r
, int,
715 (unsigned int seed
, struct random_data
*rand_state
)
716 _GL_ARG_NONNULL ((2)));
717 _GL_CXXALIAS_RPL (srandom_r
, int,
718 (unsigned int seed
, struct random_data
*rand_state
));
720 # if !@HAVE_RANDOM_R@
721 _GL_FUNCDECL_SYS (srandom_r
, int,
722 (unsigned int seed
, struct random_data
*rand_state
)
723 _GL_ARG_NONNULL ((2)));
725 _GL_CXXALIAS_SYS (srandom_r
, int,
726 (unsigned int seed
, struct random_data
*rand_state
));
728 _GL_CXXALIASWARN (srandom_r
);
729 #elif defined GNULIB_POSIXCHECK
731 # if HAVE_RAW_DECL_SRANDOM_R
732 _GL_WARN_ON_USE (srandom_r
, "srandom_r is unportable - "
733 "use gnulib module random_r for portability");
737 #if @GNULIB_RANDOM_R@
738 # if @REPLACE_RANDOM_R@
739 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
741 # define initstate_r rpl_initstate_r
743 _GL_FUNCDECL_RPL (initstate_r
, int,
744 (unsigned int seed
, char *buf
, size_t buf_size
,
745 struct random_data
*rand_state
)
746 _GL_ARG_NONNULL ((2, 4)));
747 _GL_CXXALIAS_RPL (initstate_r
, int,
748 (unsigned int seed
, char *buf
, size_t buf_size
,
749 struct random_data
*rand_state
));
751 # if !@HAVE_RANDOM_R@
752 _GL_FUNCDECL_SYS (initstate_r
, int,
753 (unsigned int seed
, char *buf
, size_t buf_size
,
754 struct random_data
*rand_state
)
755 _GL_ARG_NONNULL ((2, 4)));
757 _GL_CXXALIAS_SYS (initstate_r
, int,
758 (unsigned int seed
, char *buf
, size_t buf_size
,
759 struct random_data
*rand_state
));
761 _GL_CXXALIASWARN (initstate_r
);
762 #elif defined GNULIB_POSIXCHECK
764 # if HAVE_RAW_DECL_INITSTATE_R
765 _GL_WARN_ON_USE (initstate_r
, "initstate_r is unportable - "
766 "use gnulib module random_r for portability");
770 #if @GNULIB_RANDOM_R@
771 # if @REPLACE_RANDOM_R@
772 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
774 # define setstate_r rpl_setstate_r
776 _GL_FUNCDECL_RPL (setstate_r
, int,
777 (char *arg_state
, struct random_data
*rand_state
)
778 _GL_ARG_NONNULL ((1, 2)));
779 _GL_CXXALIAS_RPL (setstate_r
, int,
780 (char *arg_state
, struct random_data
*rand_state
));
782 # if !@HAVE_RANDOM_R@
783 _GL_FUNCDECL_SYS (setstate_r
, int,
784 (char *arg_state
, struct random_data
*rand_state
)
785 _GL_ARG_NONNULL ((1, 2)));
787 _GL_CXXALIAS_SYS (setstate_r
, int,
788 (char *arg_state
, struct random_data
*rand_state
));
790 _GL_CXXALIASWARN (setstate_r
);
791 #elif defined GNULIB_POSIXCHECK
793 # if HAVE_RAW_DECL_SETSTATE_R
794 _GL_WARN_ON_USE (setstate_r
, "setstate_r is unportable - "
795 "use gnulib module random_r for portability");
800 #if @GNULIB_REALLOC_POSIX@
801 # if @REPLACE_REALLOC@
802 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
803 || _GL_USE_STDLIB_ALLOC)
805 # define realloc rpl_realloc
807 _GL_FUNCDECL_RPL (realloc
, void *, (void *ptr
, size_t size
));
808 _GL_CXXALIAS_RPL (realloc
, void *, (void *ptr
, size_t size
));
810 _GL_CXXALIAS_SYS (realloc
, void *, (void *ptr
, size_t size
));
812 _GL_CXXALIASWARN (realloc
);
813 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
815 /* Assume realloc is always declared. */
816 _GL_WARN_ON_USE (realloc
, "realloc is not POSIX compliant everywhere - "
817 "use gnulib module realloc-posix for portability");
821 #if @GNULIB_REALLOCARRAY@
822 # if ! @HAVE_REALLOCARRAY@
823 _GL_FUNCDECL_SYS (reallocarray
, void *,
824 (void *ptr
, size_t nmemb
, size_t size
));
826 _GL_CXXALIAS_SYS (reallocarray
, void *,
827 (void *ptr
, size_t nmemb
, size_t size
));
828 _GL_CXXALIASWARN (reallocarray
);
829 #elif defined GNULIB_POSIXCHECK
831 # if HAVE_RAW_DECL_REALLOCARRAY
832 _GL_WARN_ON_USE (reallocarray
, "reallocarray is not portable - "
833 "use gnulib module reallocarray for portability");
837 #if @GNULIB_REALPATH@
838 # if @REPLACE_REALPATH@
839 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
840 # define realpath rpl_realpath
842 _GL_FUNCDECL_RPL (realpath
, char *, (const char *name
, char *resolved
)
843 _GL_ARG_NONNULL ((1)));
844 _GL_CXXALIAS_RPL (realpath
, char *, (const char *name
, char *resolved
));
846 # if !@HAVE_REALPATH@
847 _GL_FUNCDECL_SYS (realpath
, char *, (const char *name
, char *resolved
)
848 _GL_ARG_NONNULL ((1)));
850 _GL_CXXALIAS_SYS (realpath
, char *, (const char *name
, char *resolved
));
852 _GL_CXXALIASWARN (realpath
);
853 #elif defined GNULIB_POSIXCHECK
855 # if HAVE_RAW_DECL_REALPATH
856 _GL_WARN_ON_USE (realpath
, "realpath is unportable - use gnulib module "
857 "canonicalize or canonicalize-lgpl for portability");
862 /* Test a user response to a question.
863 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
865 _GL_FUNCDECL_SYS (rpmatch
, int, (const char *response
) _GL_ARG_NONNULL ((1)));
867 _GL_CXXALIAS_SYS (rpmatch
, int, (const char *response
));
868 _GL_CXXALIASWARN (rpmatch
);
869 #elif defined GNULIB_POSIXCHECK
871 # if HAVE_RAW_DECL_RPMATCH
872 _GL_WARN_ON_USE (rpmatch
, "rpmatch is unportable - "
873 "use gnulib module rpmatch for portability");
877 #if @GNULIB_SECURE_GETENV@
878 /* Look up NAME in the environment, returning 0 in insecure situations. */
879 # if !@HAVE_SECURE_GETENV@
880 _GL_FUNCDECL_SYS (secure_getenv
, char *,
881 (char const *name
) _GL_ARG_NONNULL ((1)));
883 _GL_CXXALIAS_SYS (secure_getenv
, char *, (char const *name
));
884 _GL_CXXALIASWARN (secure_getenv
);
885 #elif defined GNULIB_POSIXCHECK
886 # undef secure_getenv
887 # if HAVE_RAW_DECL_SECURE_GETENV
888 _GL_WARN_ON_USE (secure_getenv
, "secure_getenv is unportable - "
889 "use gnulib module secure_getenv for portability");
894 /* Set NAME to VALUE in the environment.
895 If REPLACE is nonzero, overwrite an existing value. */
896 # if @REPLACE_SETENV@
897 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
899 # define setenv rpl_setenv
901 _GL_FUNCDECL_RPL (setenv
, int,
902 (const char *name
, const char *value
, int replace
)
903 _GL_ARG_NONNULL ((1)));
904 _GL_CXXALIAS_RPL (setenv
, int,
905 (const char *name
, const char *value
, int replace
));
907 # if !@HAVE_DECL_SETENV@
908 _GL_FUNCDECL_SYS (setenv
, int,
909 (const char *name
, const char *value
, int replace
)
910 _GL_ARG_NONNULL ((1)));
912 _GL_CXXALIAS_SYS (setenv
, int,
913 (const char *name
, const char *value
, int replace
));
915 # if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
916 _GL_CXXALIASWARN (setenv
);
918 #elif defined GNULIB_POSIXCHECK
920 # if HAVE_RAW_DECL_SETENV
921 _GL_WARN_ON_USE (setenv
, "setenv is unportable - "
922 "use gnulib module setenv for portability");
927 /* Parse a double from STRING, updating ENDP if appropriate. */
928 # if @REPLACE_STRTOD@
929 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
930 # define strtod rpl_strtod
932 _GL_FUNCDECL_RPL (strtod
, double, (const char *str
, char **endp
)
933 _GL_ARG_NONNULL ((1)));
934 _GL_CXXALIAS_RPL (strtod
, double, (const char *str
, char **endp
));
937 _GL_FUNCDECL_SYS (strtod
, double, (const char *str
, char **endp
)
938 _GL_ARG_NONNULL ((1)));
940 _GL_CXXALIAS_SYS (strtod
, double, (const char *str
, char **endp
));
942 _GL_CXXALIASWARN (strtod
);
943 #elif defined GNULIB_POSIXCHECK
945 # if HAVE_RAW_DECL_STRTOD
946 _GL_WARN_ON_USE (strtod
, "strtod is unportable - "
947 "use gnulib module strtod for portability");
952 /* Parse a signed integer whose textual representation starts at STRING.
953 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
954 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
956 If ENDPTR is not NULL, the address of the first byte after the integer is
958 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
961 _GL_FUNCDECL_SYS (strtoll
, long long,
962 (const char *string
, char **endptr
, int base
)
963 _GL_ARG_NONNULL ((1)));
965 _GL_CXXALIAS_SYS (strtoll
, long long,
966 (const char *string
, char **endptr
, int base
));
967 _GL_CXXALIASWARN (strtoll
);
968 #elif defined GNULIB_POSIXCHECK
970 # if HAVE_RAW_DECL_STRTOLL
971 _GL_WARN_ON_USE (strtoll
, "strtoll is unportable - "
972 "use gnulib module strtoll for portability");
976 #if @GNULIB_STRTOULL@
977 /* Parse an unsigned integer whose textual representation starts at STRING.
978 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
979 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
981 If ENDPTR is not NULL, the address of the first byte after the integer is
983 Upon overflow, the return value is ULLONG_MAX, and errno is set to
985 # if !@HAVE_STRTOULL@
986 _GL_FUNCDECL_SYS (strtoull
, unsigned long long,
987 (const char *string
, char **endptr
, int base
)
988 _GL_ARG_NONNULL ((1)));
990 _GL_CXXALIAS_SYS (strtoull
, unsigned long long,
991 (const char *string
, char **endptr
, int base
));
992 _GL_CXXALIASWARN (strtoull
);
993 #elif defined GNULIB_POSIXCHECK
995 # if HAVE_RAW_DECL_STRTOULL
996 _GL_WARN_ON_USE (strtoull
, "strtoull is unportable - "
997 "use gnulib module strtoull for portability");
1001 #if @GNULIB_UNLOCKPT@
1002 /* Unlock the slave side of the pseudo-terminal whose master side is specified
1003 by FD, so that it can be opened. */
1004 # if !@HAVE_UNLOCKPT@
1005 _GL_FUNCDECL_SYS (unlockpt
, int, (int fd
));
1007 _GL_CXXALIAS_SYS (unlockpt
, int, (int fd
));
1008 _GL_CXXALIASWARN (unlockpt
);
1009 #elif defined GNULIB_POSIXCHECK
1011 # if HAVE_RAW_DECL_UNLOCKPT
1012 _GL_WARN_ON_USE (unlockpt
, "unlockpt is not portable - "
1013 "use gnulib module unlockpt for portability");
1017 #if @GNULIB_UNSETENV@
1018 /* Remove the variable NAME from the environment. */
1019 # if @REPLACE_UNSETENV@
1020 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1022 # define unsetenv rpl_unsetenv
1024 _GL_FUNCDECL_RPL (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1025 _GL_CXXALIAS_RPL (unsetenv
, int, (const char *name
));
1027 # if !@HAVE_DECL_UNSETENV@
1028 _GL_FUNCDECL_SYS (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1030 _GL_CXXALIAS_SYS (unsetenv
, int, (const char *name
));
1032 # if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
1033 _GL_CXXALIASWARN (unsetenv
);
1035 #elif defined GNULIB_POSIXCHECK
1037 # if HAVE_RAW_DECL_UNSETENV
1038 _GL_WARN_ON_USE (unsetenv
, "unsetenv is unportable - "
1039 "use gnulib module unsetenv for portability");
1043 /* Convert a wide character to a multibyte character. */
1045 # if @REPLACE_WCTOMB@
1046 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1048 # define wctomb rpl_wctomb
1050 _GL_FUNCDECL_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1051 _GL_CXXALIAS_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1053 _GL_CXXALIAS_SYS (wctomb
, int, (char *s
, wchar_t wc
));
1055 _GL_CXXALIASWARN (wctomb
);
1059 #endif /* _@GUARD_PREFIX@_STDLIB_H */
1060 #endif /* _@GUARD_PREFIX@_STDLIB_H */