1 /* A GNU-like <stdlib.h>.
3 Copyright (C) 1995, 2001-2004, 2006-2020 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 #ifndef _GL_ATTRIBUTE_PURE
105 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
106 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
108 # define _GL_ATTRIBUTE_PURE /* empty */
112 /* The definition of _Noreturn is copied here. */
114 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
116 /* The definition of _GL_ARG_NONNULL is copied here. */
118 /* The definition of _GL_WARN_ON_USE is copied here. */
121 /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
123 # define EXIT_SUCCESS 0
125 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
126 with proper operation of xargs. */
128 # define EXIT_FAILURE 1
129 #elif EXIT_FAILURE != 1
131 # define EXIT_FAILURE 1
136 /* Terminate the current process with the given return code, without running
137 the 'atexit' handlers. */
139 _GL_FUNCDECL_SYS (_Exit
, _Noreturn
void, (int status
));
141 _GL_CXXALIAS_SYS (_Exit
, void, (int status
));
142 _GL_CXXALIASWARN (_Exit
);
143 #elif defined GNULIB_POSIXCHECK
145 # if HAVE_RAW_DECL__EXIT
146 _GL_WARN_ON_USE (_Exit
, "_Exit is unportable - "
147 "use gnulib module _Exit for portability");
153 /* Parse a signed decimal integer.
154 Returns the value of the integer. Errors are not detected. */
156 _GL_FUNCDECL_SYS (atoll
, long long, (const char *string
)
158 _GL_ARG_NONNULL ((1)));
160 _GL_CXXALIAS_SYS (atoll
, long long, (const char *string
));
161 _GL_CXXALIASWARN (atoll
);
162 #elif defined GNULIB_POSIXCHECK
164 # if HAVE_RAW_DECL_ATOLL
165 _GL_WARN_ON_USE (atoll
, "atoll is unportable - "
166 "use gnulib module atoll for portability");
170 #if @GNULIB_CALLOC_POSIX@
171 # if @REPLACE_CALLOC@
172 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
174 # define calloc rpl_calloc
176 _GL_FUNCDECL_RPL (calloc
, void *, (size_t nmemb
, size_t size
));
177 _GL_CXXALIAS_RPL (calloc
, void *, (size_t nmemb
, size_t size
));
179 _GL_CXXALIAS_SYS (calloc
, void *, (size_t nmemb
, size_t size
));
182 _GL_CXXALIASWARN (calloc
);
184 #elif defined GNULIB_POSIXCHECK
186 /* Assume calloc is always declared. */
187 _GL_WARN_ON_USE (calloc
, "calloc is not POSIX compliant everywhere - "
188 "use gnulib module calloc-posix for portability");
191 #if @GNULIB_CANONICALIZE_FILE_NAME@
192 # if @REPLACE_CANONICALIZE_FILE_NAME@
193 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
194 # define canonicalize_file_name rpl_canonicalize_file_name
196 _GL_FUNCDECL_RPL (canonicalize_file_name
, char *, (const char *name
)
197 _GL_ARG_NONNULL ((1)));
198 _GL_CXXALIAS_RPL (canonicalize_file_name
, char *, (const char *name
));
200 # if !@HAVE_CANONICALIZE_FILE_NAME@
201 _GL_FUNCDECL_SYS (canonicalize_file_name
, char *, (const char *name
)
202 _GL_ARG_NONNULL ((1)));
204 _GL_CXXALIAS_SYS (canonicalize_file_name
, char *, (const char *name
));
206 # ifndef GNULIB_defined_canonicalize_file_name
207 # define GNULIB_defined_canonicalize_file_name \
208 (!@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@)
210 _GL_CXXALIASWARN (canonicalize_file_name
);
211 #elif defined GNULIB_POSIXCHECK
212 # undef canonicalize_file_name
213 # if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
214 _GL_WARN_ON_USE (canonicalize_file_name
,
215 "canonicalize_file_name is unportable - "
216 "use gnulib module canonicalize-lgpl for portability");
220 #if defined _WIN32 && !defined __CYGWIN__
225 #if defined _WIN32 && !defined __CYGWIN__
230 #if defined _WIN32 && !defined __CYGWIN__
235 #if @GNULIB_GETLOADAVG@
236 /* Store max(NELEM,3) load average numbers in LOADAVG[].
237 The three numbers are the load average of the last 1 minute, the last 5
238 minutes, and the last 15 minutes, respectively.
239 LOADAVG is an array of NELEM numbers. */
240 # if !@HAVE_DECL_GETLOADAVG@
241 _GL_FUNCDECL_SYS (getloadavg
, int, (double loadavg
[], int nelem
)
242 _GL_ARG_NONNULL ((1)));
244 _GL_CXXALIAS_SYS (getloadavg
, int, (double loadavg
[], int nelem
));
245 _GL_CXXALIASWARN (getloadavg
);
246 #elif defined GNULIB_POSIXCHECK
248 # if HAVE_RAW_DECL_GETLOADAVG
249 _GL_WARN_ON_USE (getloadavg
, "getloadavg is not portable - "
250 "use gnulib module getloadavg for portability");
254 #if @GNULIB_GETSUBOPT@
255 /* Assuming *OPTIONP is a comma separated list of elements of the form
256 "token" or "token=value", getsubopt parses the first of these elements.
257 If the first element refers to a "token" that is member of the given
258 NULL-terminated array of tokens:
259 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
260 the first option and the comma, sets *VALUEP to the value of the
261 element (or NULL if it doesn't contain an "=" sign),
262 - It returns the index of the "token" in the given array of tokens.
263 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
264 For more details see the POSIX specification.
265 https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsubopt.html */
266 # if !@HAVE_GETSUBOPT@
267 _GL_FUNCDECL_SYS (getsubopt
, int,
268 (char **optionp
, char *const *tokens
, char **valuep
)
269 _GL_ARG_NONNULL ((1, 2, 3)));
271 _GL_CXXALIAS_SYS (getsubopt
, int,
272 (char **optionp
, char *const *tokens
, char **valuep
));
273 _GL_CXXALIASWARN (getsubopt
);
274 #elif defined GNULIB_POSIXCHECK
276 # if HAVE_RAW_DECL_GETSUBOPT
277 _GL_WARN_ON_USE (getsubopt
, "getsubopt is unportable - "
278 "use gnulib module getsubopt for portability");
283 /* Change the ownership and access permission of the slave side of the
284 pseudo-terminal whose master side is specified by FD. */
286 _GL_FUNCDECL_SYS (grantpt
, int, (int fd
));
288 _GL_CXXALIAS_SYS (grantpt
, int, (int fd
));
289 _GL_CXXALIASWARN (grantpt
);
290 #elif defined GNULIB_POSIXCHECK
292 # if HAVE_RAW_DECL_GRANTPT
293 _GL_WARN_ON_USE (grantpt
, "grantpt is not portable - "
294 "use gnulib module grantpt for portability");
298 /* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
299 rely on GNU or POSIX semantics for malloc and realloc (for example,
300 by never specifying a zero size), so it does not need malloc or
301 realloc to be redefined. */
302 #if @GNULIB_MALLOC_POSIX@
303 # if @REPLACE_MALLOC@
304 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
305 || _GL_USE_STDLIB_ALLOC)
307 # define malloc rpl_malloc
309 _GL_FUNCDECL_RPL (malloc
, void *, (size_t size
));
310 _GL_CXXALIAS_RPL (malloc
, void *, (size_t size
));
312 _GL_CXXALIAS_SYS (malloc
, void *, (size_t size
));
315 _GL_CXXALIASWARN (malloc
);
317 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
319 /* Assume malloc is always declared. */
320 _GL_WARN_ON_USE (malloc
, "malloc is not POSIX compliant everywhere - "
321 "use gnulib module malloc-posix for portability");
324 /* Convert a multibyte character to a wide character. */
326 # if @REPLACE_MBTOWC@
327 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
329 # define mbtowc rpl_mbtowc
331 _GL_FUNCDECL_RPL (mbtowc
, int,
332 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
333 _GL_CXXALIAS_RPL (mbtowc
, int,
334 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
337 _GL_FUNCDECL_SYS (mbtowc
, int,
338 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
340 _GL_CXXALIAS_SYS (mbtowc
, int,
341 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
344 _GL_CXXALIASWARN (mbtowc
);
346 #elif defined GNULIB_POSIXCHECK
348 # if HAVE_RAW_DECL_MBTOWC
349 _GL_WARN_ON_USE (mbtowc
, "mbtowc is not portable - "
350 "use gnulib module mbtowc for portability");
355 /* Create a unique temporary directory from TEMPLATE.
356 The last six characters of TEMPLATE must be "XXXXXX";
357 they are replaced with a string that makes the directory name unique.
358 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
359 The directory is created mode 700. */
361 _GL_FUNCDECL_SYS (mkdtemp
, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
363 _GL_CXXALIAS_SYS (mkdtemp
, char *, (char * /*template*/));
364 _GL_CXXALIASWARN (mkdtemp
);
365 #elif defined GNULIB_POSIXCHECK
367 # if HAVE_RAW_DECL_MKDTEMP
368 _GL_WARN_ON_USE (mkdtemp
, "mkdtemp is unportable - "
369 "use gnulib module mkdtemp for portability");
373 #if @GNULIB_MKOSTEMP@
374 /* Create a unique temporary file from TEMPLATE.
375 The last six characters of TEMPLATE must be "XXXXXX";
376 they are replaced with a string that makes the file name unique.
377 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
378 and O_TEXT, O_BINARY (defined in "binary-io.h").
379 The file is then created, with the specified flags, ensuring it didn't exist
381 The file is created read-write (mask at least 0600 & ~umask), but it may be
382 world-readable and world-writable (mask 0666 & ~umask), depending on the
384 Returns the open file descriptor if successful, otherwise -1 and errno
386 # if !@HAVE_MKOSTEMP@
387 _GL_FUNCDECL_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/)
388 _GL_ARG_NONNULL ((1)));
390 _GL_CXXALIAS_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/));
391 _GL_CXXALIASWARN (mkostemp
);
392 #elif defined GNULIB_POSIXCHECK
394 # if HAVE_RAW_DECL_MKOSTEMP
395 _GL_WARN_ON_USE (mkostemp
, "mkostemp is unportable - "
396 "use gnulib module mkostemp for portability");
400 #if @GNULIB_MKOSTEMPS@
401 /* Create a unique temporary file from TEMPLATE.
402 The last six characters of TEMPLATE before a suffix of length
403 SUFFIXLEN must be "XXXXXX";
404 they are replaced with a string that makes the file name unique.
405 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
406 and O_TEXT, O_BINARY (defined in "binary-io.h").
407 The file is then created, with the specified flags, ensuring it didn't exist
409 The file is created read-write (mask at least 0600 & ~umask), but it may be
410 world-readable and world-writable (mask 0666 & ~umask), depending on the
412 Returns the open file descriptor if successful, otherwise -1 and errno
414 # if !@HAVE_MKOSTEMPS@
415 _GL_FUNCDECL_SYS (mkostemps
, int,
416 (char * /*template*/, int /*suffixlen*/, int /*flags*/)
417 _GL_ARG_NONNULL ((1)));
419 _GL_CXXALIAS_SYS (mkostemps
, int,
420 (char * /*template*/, int /*suffixlen*/, int /*flags*/));
421 _GL_CXXALIASWARN (mkostemps
);
422 #elif defined GNULIB_POSIXCHECK
424 # if HAVE_RAW_DECL_MKOSTEMPS
425 _GL_WARN_ON_USE (mkostemps
, "mkostemps is unportable - "
426 "use gnulib module mkostemps for portability");
431 /* Create a unique temporary file from TEMPLATE.
432 The last six characters of TEMPLATE must be "XXXXXX";
433 they are replaced with a string that makes the file name unique.
434 The file is then created, ensuring it didn't exist before.
435 The file is created read-write (mask at least 0600 & ~umask), but it may be
436 world-readable and world-writable (mask 0666 & ~umask), depending on the
438 Returns the open file descriptor if successful, otherwise -1 and errno
440 # if @REPLACE_MKSTEMP@
441 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
442 # define mkstemp rpl_mkstemp
444 _GL_FUNCDECL_RPL (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
445 _GL_CXXALIAS_RPL (mkstemp
, int, (char * /*template*/));
447 # if ! @HAVE_MKSTEMP@
448 _GL_FUNCDECL_SYS (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
450 _GL_CXXALIAS_SYS (mkstemp
, int, (char * /*template*/));
452 _GL_CXXALIASWARN (mkstemp
);
453 #elif defined GNULIB_POSIXCHECK
455 # if HAVE_RAW_DECL_MKSTEMP
456 _GL_WARN_ON_USE (mkstemp
, "mkstemp is unportable - "
457 "use gnulib module mkstemp for portability");
461 #if @GNULIB_MKSTEMPS@
462 /* Create a unique temporary file from TEMPLATE.
463 The last six characters of TEMPLATE prior to a suffix of length
464 SUFFIXLEN must be "XXXXXX";
465 they are replaced with a string that makes the file name unique.
466 The file is then created, ensuring it didn't exist before.
467 The file is created read-write (mask at least 0600 & ~umask), but it may be
468 world-readable and world-writable (mask 0666 & ~umask), depending on the
470 Returns the open file descriptor if successful, otherwise -1 and errno
472 # if !@HAVE_MKSTEMPS@
473 _GL_FUNCDECL_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/)
474 _GL_ARG_NONNULL ((1)));
476 _GL_CXXALIAS_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/));
477 _GL_CXXALIASWARN (mkstemps
);
478 #elif defined GNULIB_POSIXCHECK
480 # if HAVE_RAW_DECL_MKSTEMPS
481 _GL_WARN_ON_USE (mkstemps
, "mkstemps is unportable - "
482 "use gnulib module mkstemps for portability");
486 #if defined _WIN32 && !defined __CYGWIN__
488 # define mktemp _mktemp
491 #if @GNULIB_POSIX_OPENPT@
492 /* Return an FD open to the master side of a pseudo-terminal. Flags should
493 include O_RDWR, and may also include O_NOCTTY. */
494 # if !@HAVE_POSIX_OPENPT@
495 _GL_FUNCDECL_SYS (posix_openpt
, int, (int flags
));
497 _GL_CXXALIAS_SYS (posix_openpt
, int, (int flags
));
498 _GL_CXXALIASWARN (posix_openpt
);
499 #elif defined GNULIB_POSIXCHECK
501 # if HAVE_RAW_DECL_POSIX_OPENPT
502 _GL_WARN_ON_USE (posix_openpt
, "posix_openpt is not portable - "
503 "use gnulib module posix_openpt for portability");
508 /* Return the pathname of the pseudo-terminal slave associated with
509 the master FD is open on, or NULL on errors. */
510 # if @REPLACE_PTSNAME@
511 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
513 # define ptsname rpl_ptsname
515 _GL_FUNCDECL_RPL (ptsname
, char *, (int fd
));
516 _GL_CXXALIAS_RPL (ptsname
, char *, (int fd
));
519 _GL_FUNCDECL_SYS (ptsname
, char *, (int fd
));
521 _GL_CXXALIAS_SYS (ptsname
, char *, (int fd
));
523 _GL_CXXALIASWARN (ptsname
);
524 #elif defined GNULIB_POSIXCHECK
526 # if HAVE_RAW_DECL_PTSNAME
527 _GL_WARN_ON_USE (ptsname
, "ptsname is not portable - "
528 "use gnulib module ptsname for portability");
532 #if @GNULIB_PTSNAME_R@
533 /* Set the pathname of the pseudo-terminal slave associated with
534 the master FD is open on and return 0, or set errno and return
535 non-zero on errors. */
536 # if @REPLACE_PTSNAME_R@
537 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
539 # define ptsname_r rpl_ptsname_r
541 _GL_FUNCDECL_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
542 _GL_CXXALIAS_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
544 # if !@HAVE_PTSNAME_R@
545 _GL_FUNCDECL_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
547 _GL_CXXALIAS_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
549 # ifndef GNULIB_defined_ptsname_r
550 # define GNULIB_defined_ptsname_r (!@HAVE_PTSNAME_R@ || @REPLACE_PTSNAME_R@)
552 _GL_CXXALIASWARN (ptsname_r
);
553 #elif defined GNULIB_POSIXCHECK
555 # if HAVE_RAW_DECL_PTSNAME_R
556 _GL_WARN_ON_USE (ptsname_r
, "ptsname_r is not portable - "
557 "use gnulib module ptsname_r for portability");
562 # if @REPLACE_PUTENV@
563 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
565 # define putenv rpl_putenv
567 _GL_FUNCDECL_RPL (putenv
, int, (char *string
) _GL_ARG_NONNULL ((1)));
568 _GL_CXXALIAS_RPL (putenv
, int, (char *string
));
569 # elif defined _WIN32 && !defined __CYGWIN__
570 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
572 # define putenv _putenv
574 _GL_CXXALIAS_MDA (putenv
, int, (char *string
));
576 _GL_CXXALIAS_SYS (putenv
, int, (char *string
));
578 _GL_CXXALIASWARN (putenv
);
579 #elif defined _WIN32 && !defined __CYGWIN__
581 # define putenv _putenv
585 /* Sort an array of NMEMB elements, starting at address BASE, each element
586 occupying SIZE bytes, in ascending order according to the comparison
588 # if @REPLACE_QSORT_R@
589 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
591 # define qsort_r rpl_qsort_r
593 _GL_FUNCDECL_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
594 int (*compare
) (void const *, void const *,
596 void *arg
) _GL_ARG_NONNULL ((1, 4)));
597 _GL_CXXALIAS_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
598 int (*compare
) (void const *, void const *,
603 _GL_FUNCDECL_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
604 int (*compare
) (void const *, void const *,
606 void *arg
) _GL_ARG_NONNULL ((1, 4)));
608 _GL_CXXALIAS_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
609 int (*compare
) (void const *, void const *,
613 _GL_CXXALIASWARN (qsort_r
);
614 #elif defined GNULIB_POSIXCHECK
616 # if HAVE_RAW_DECL_QSORT_R
617 _GL_WARN_ON_USE (qsort_r
, "qsort_r is not portable - "
618 "use gnulib module qsort_r for portability");
623 #if @GNULIB_RANDOM_R@
624 # if !@HAVE_RANDOM_R@
626 # define RAND_MAX 2147483647
633 # if @REPLACE_RANDOM@
634 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
636 # define random rpl_random
638 _GL_FUNCDECL_RPL (random
, long, (void));
639 _GL_CXXALIAS_RPL (random
, long, (void));
642 _GL_FUNCDECL_SYS (random
, long, (void));
644 /* Need to cast, because on Haiku, the return type is
646 _GL_CXXALIAS_SYS_CAST (random
, long, (void));
648 _GL_CXXALIASWARN (random
);
649 #elif defined GNULIB_POSIXCHECK
651 # if HAVE_RAW_DECL_RANDOM
652 _GL_WARN_ON_USE (random
, "random is unportable - "
653 "use gnulib module random for portability");
658 # if @REPLACE_RANDOM@
659 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
661 # define srandom rpl_srandom
663 _GL_FUNCDECL_RPL (srandom
, void, (unsigned int seed
));
664 _GL_CXXALIAS_RPL (srandom
, void, (unsigned int seed
));
667 _GL_FUNCDECL_SYS (srandom
, void, (unsigned int seed
));
669 /* Need to cast, because on FreeBSD, the first parameter is
670 unsigned long seed. */
671 _GL_CXXALIAS_SYS_CAST (srandom
, void, (unsigned int seed
));
673 _GL_CXXALIASWARN (srandom
);
674 #elif defined GNULIB_POSIXCHECK
676 # if HAVE_RAW_DECL_SRANDOM
677 _GL_WARN_ON_USE (srandom
, "srandom is unportable - "
678 "use gnulib module random for portability");
683 # if @REPLACE_INITSTATE@
684 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
686 # define initstate rpl_initstate
688 _GL_FUNCDECL_RPL (initstate
, char *,
689 (unsigned int seed
, char *buf
, size_t buf_size
)
690 _GL_ARG_NONNULL ((2)));
691 _GL_CXXALIAS_RPL (initstate
, char *,
692 (unsigned int seed
, char *buf
, size_t buf_size
));
694 # if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
695 _GL_FUNCDECL_SYS (initstate
, char *,
696 (unsigned int seed
, char *buf
, size_t buf_size
)
697 _GL_ARG_NONNULL ((2)));
699 /* Need to cast, because on FreeBSD, the first parameter is
700 unsigned long seed. */
701 _GL_CXXALIAS_SYS_CAST (initstate
, char *,
702 (unsigned int seed
, char *buf
, size_t buf_size
));
704 _GL_CXXALIASWARN (initstate
);
705 #elif defined GNULIB_POSIXCHECK
707 # if HAVE_RAW_DECL_INITSTATE
708 _GL_WARN_ON_USE (initstate
, "initstate is unportable - "
709 "use gnulib module random for portability");
714 # if @REPLACE_SETSTATE@
715 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
717 # define setstate rpl_setstate
719 _GL_FUNCDECL_RPL (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
720 _GL_CXXALIAS_RPL (setstate
, char *, (char *arg_state
));
722 # if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
723 _GL_FUNCDECL_SYS (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
725 /* Need to cast, because on Mac OS X 10.13, HP-UX, Solaris the first parameter
726 is const char *arg_state. */
727 _GL_CXXALIAS_SYS_CAST (setstate
, char *, (char *arg_state
));
729 _GL_CXXALIASWARN (setstate
);
730 #elif defined GNULIB_POSIXCHECK
732 # if HAVE_RAW_DECL_SETSTATE
733 _GL_WARN_ON_USE (setstate
, "setstate is unportable - "
734 "use gnulib module random for portability");
739 #if @GNULIB_RANDOM_R@
740 # if @REPLACE_RANDOM_R@
741 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
743 # define random_r rpl_random_r
745 _GL_FUNCDECL_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
)
746 _GL_ARG_NONNULL ((1, 2)));
747 _GL_CXXALIAS_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
));
749 # if !@HAVE_RANDOM_R@
750 _GL_FUNCDECL_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
)
751 _GL_ARG_NONNULL ((1, 2)));
753 _GL_CXXALIAS_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
));
755 _GL_CXXALIASWARN (random_r
);
756 #elif defined GNULIB_POSIXCHECK
758 # if HAVE_RAW_DECL_RANDOM_R
759 _GL_WARN_ON_USE (random_r
, "random_r is unportable - "
760 "use gnulib module random_r for portability");
764 #if @GNULIB_RANDOM_R@
765 # if @REPLACE_RANDOM_R@
766 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
768 # define srandom_r rpl_srandom_r
770 _GL_FUNCDECL_RPL (srandom_r
, int,
771 (unsigned int seed
, struct random_data
*rand_state
)
772 _GL_ARG_NONNULL ((2)));
773 _GL_CXXALIAS_RPL (srandom_r
, int,
774 (unsigned int seed
, struct random_data
*rand_state
));
776 # if !@HAVE_RANDOM_R@
777 _GL_FUNCDECL_SYS (srandom_r
, int,
778 (unsigned int seed
, struct random_data
*rand_state
)
779 _GL_ARG_NONNULL ((2)));
781 _GL_CXXALIAS_SYS (srandom_r
, int,
782 (unsigned int seed
, struct random_data
*rand_state
));
784 _GL_CXXALIASWARN (srandom_r
);
785 #elif defined GNULIB_POSIXCHECK
787 # if HAVE_RAW_DECL_SRANDOM_R
788 _GL_WARN_ON_USE (srandom_r
, "srandom_r is unportable - "
789 "use gnulib module random_r for portability");
793 #if @GNULIB_RANDOM_R@
794 # if @REPLACE_RANDOM_R@
795 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
797 # define initstate_r rpl_initstate_r
799 _GL_FUNCDECL_RPL (initstate_r
, int,
800 (unsigned int seed
, char *buf
, size_t buf_size
,
801 struct random_data
*rand_state
)
802 _GL_ARG_NONNULL ((2, 4)));
803 _GL_CXXALIAS_RPL (initstate_r
, int,
804 (unsigned int seed
, char *buf
, size_t buf_size
,
805 struct random_data
*rand_state
));
807 # if !@HAVE_RANDOM_R@
808 _GL_FUNCDECL_SYS (initstate_r
, int,
809 (unsigned int seed
, char *buf
, size_t buf_size
,
810 struct random_data
*rand_state
)
811 _GL_ARG_NONNULL ((2, 4)));
813 /* Need to cast, because on Haiku, the third parameter is
814 unsigned long buf_size. */
815 _GL_CXXALIAS_SYS_CAST (initstate_r
, int,
816 (unsigned int seed
, char *buf
, size_t buf_size
,
817 struct random_data
*rand_state
));
819 _GL_CXXALIASWARN (initstate_r
);
820 #elif defined GNULIB_POSIXCHECK
822 # if HAVE_RAW_DECL_INITSTATE_R
823 _GL_WARN_ON_USE (initstate_r
, "initstate_r is unportable - "
824 "use gnulib module random_r for portability");
828 #if @GNULIB_RANDOM_R@
829 # if @REPLACE_RANDOM_R@
830 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
832 # define setstate_r rpl_setstate_r
834 _GL_FUNCDECL_RPL (setstate_r
, int,
835 (char *arg_state
, struct random_data
*rand_state
)
836 _GL_ARG_NONNULL ((1, 2)));
837 _GL_CXXALIAS_RPL (setstate_r
, int,
838 (char *arg_state
, struct random_data
*rand_state
));
840 # if !@HAVE_RANDOM_R@
841 _GL_FUNCDECL_SYS (setstate_r
, int,
842 (char *arg_state
, struct random_data
*rand_state
)
843 _GL_ARG_NONNULL ((1, 2)));
845 /* Need to cast, because on Haiku, the first parameter is
847 _GL_CXXALIAS_SYS_CAST (setstate_r
, int,
848 (char *arg_state
, struct random_data
*rand_state
));
850 _GL_CXXALIASWARN (setstate_r
);
851 #elif defined GNULIB_POSIXCHECK
853 # if HAVE_RAW_DECL_SETSTATE_R
854 _GL_WARN_ON_USE (setstate_r
, "setstate_r is unportable - "
855 "use gnulib module random_r for portability");
860 #if @GNULIB_REALLOC_POSIX@
861 # if @REPLACE_REALLOC@
862 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
863 || _GL_USE_STDLIB_ALLOC)
865 # define realloc rpl_realloc
867 _GL_FUNCDECL_RPL (realloc
, void *, (void *ptr
, size_t size
));
868 _GL_CXXALIAS_RPL (realloc
, void *, (void *ptr
, size_t size
));
870 _GL_CXXALIAS_SYS (realloc
, void *, (void *ptr
, size_t size
));
873 _GL_CXXALIASWARN (realloc
);
875 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
877 /* Assume realloc is always declared. */
878 _GL_WARN_ON_USE (realloc
, "realloc is not POSIX compliant everywhere - "
879 "use gnulib module realloc-posix for portability");
883 #if @GNULIB_REALLOCARRAY@
884 # if ! @HAVE_REALLOCARRAY@
885 _GL_FUNCDECL_SYS (reallocarray
, void *,
886 (void *ptr
, size_t nmemb
, size_t size
));
888 _GL_CXXALIAS_SYS (reallocarray
, void *,
889 (void *ptr
, size_t nmemb
, size_t size
));
890 _GL_CXXALIASWARN (reallocarray
);
891 #elif defined GNULIB_POSIXCHECK
893 # if HAVE_RAW_DECL_REALLOCARRAY
894 _GL_WARN_ON_USE (reallocarray
, "reallocarray is not portable - "
895 "use gnulib module reallocarray for portability");
899 #if @GNULIB_REALPATH@
900 # if @REPLACE_REALPATH@
901 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
902 # define realpath rpl_realpath
904 _GL_FUNCDECL_RPL (realpath
, char *,
905 (const char *restrict name
, char *restrict resolved
)
906 _GL_ARG_NONNULL ((1)));
907 _GL_CXXALIAS_RPL (realpath
, char *,
908 (const char *restrict name
, char *restrict resolved
));
910 # if !@HAVE_REALPATH@
911 _GL_FUNCDECL_SYS (realpath
, char *,
912 (const char *restrict name
, char *restrict resolved
)
913 _GL_ARG_NONNULL ((1)));
915 _GL_CXXALIAS_SYS (realpath
, char *,
916 (const char *restrict name
, char *restrict resolved
));
918 _GL_CXXALIASWARN (realpath
);
919 #elif defined GNULIB_POSIXCHECK
921 # if HAVE_RAW_DECL_REALPATH
922 _GL_WARN_ON_USE (realpath
, "realpath is unportable - use gnulib module "
923 "canonicalize or canonicalize-lgpl for portability");
928 /* Test a user response to a question.
929 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
931 _GL_FUNCDECL_SYS (rpmatch
, int, (const char *response
) _GL_ARG_NONNULL ((1)));
933 _GL_CXXALIAS_SYS (rpmatch
, int, (const char *response
));
934 _GL_CXXALIASWARN (rpmatch
);
935 #elif defined GNULIB_POSIXCHECK
937 # if HAVE_RAW_DECL_RPMATCH
938 _GL_WARN_ON_USE (rpmatch
, "rpmatch is unportable - "
939 "use gnulib module rpmatch for portability");
943 #if @GNULIB_SECURE_GETENV@
944 /* Look up NAME in the environment, returning 0 in insecure situations. */
945 # if !@HAVE_SECURE_GETENV@
946 _GL_FUNCDECL_SYS (secure_getenv
, char *,
947 (char const *name
) _GL_ARG_NONNULL ((1)));
949 _GL_CXXALIAS_SYS (secure_getenv
, char *, (char const *name
));
950 _GL_CXXALIASWARN (secure_getenv
);
951 #elif defined GNULIB_POSIXCHECK
952 # undef secure_getenv
953 # if HAVE_RAW_DECL_SECURE_GETENV
954 _GL_WARN_ON_USE (secure_getenv
, "secure_getenv is unportable - "
955 "use gnulib module secure_getenv for portability");
960 /* Set NAME to VALUE in the environment.
961 If REPLACE is nonzero, overwrite an existing value. */
962 # if @REPLACE_SETENV@
963 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
965 # define setenv rpl_setenv
967 _GL_FUNCDECL_RPL (setenv
, int,
968 (const char *name
, const char *value
, int replace
)
969 _GL_ARG_NONNULL ((1)));
970 _GL_CXXALIAS_RPL (setenv
, int,
971 (const char *name
, const char *value
, int replace
));
973 # if !@HAVE_DECL_SETENV@
974 _GL_FUNCDECL_SYS (setenv
, int,
975 (const char *name
, const char *value
, int replace
)
976 _GL_ARG_NONNULL ((1)));
978 _GL_CXXALIAS_SYS (setenv
, int,
979 (const char *name
, const char *value
, int replace
));
981 # if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
982 _GL_CXXALIASWARN (setenv
);
984 #elif defined GNULIB_POSIXCHECK
986 # if HAVE_RAW_DECL_SETENV
987 _GL_WARN_ON_USE (setenv
, "setenv is unportable - "
988 "use gnulib module setenv for portability");
993 /* Parse a double from STRING, updating ENDP if appropriate. */
994 # if @REPLACE_STRTOD@
995 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
996 # define strtod rpl_strtod
998 # define GNULIB_defined_strtod_function 1
999 _GL_FUNCDECL_RPL (strtod
, double,
1000 (const char *restrict str
, char **restrict endp
)
1001 _GL_ARG_NONNULL ((1)));
1002 _GL_CXXALIAS_RPL (strtod
, double,
1003 (const char *restrict str
, char **restrict endp
));
1006 _GL_FUNCDECL_SYS (strtod
, double,
1007 (const char *restrict str
, char **restrict endp
)
1008 _GL_ARG_NONNULL ((1)));
1010 _GL_CXXALIAS_SYS (strtod
, double,
1011 (const char *restrict str
, char **restrict endp
));
1014 _GL_CXXALIASWARN (strtod
);
1016 #elif defined GNULIB_POSIXCHECK
1018 # if HAVE_RAW_DECL_STRTOD
1019 _GL_WARN_ON_USE (strtod
, "strtod is unportable - "
1020 "use gnulib module strtod for portability");
1024 #if @GNULIB_STRTOLD@
1025 /* Parse a 'long double' from STRING, updating ENDP if appropriate. */
1026 # if @REPLACE_STRTOLD@
1027 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1028 # define strtold rpl_strtold
1030 # define GNULIB_defined_strtold_function 1
1031 _GL_FUNCDECL_RPL (strtold
, long double,
1032 (const char *restrict str
, char **restrict endp
)
1033 _GL_ARG_NONNULL ((1)));
1034 _GL_CXXALIAS_RPL (strtold
, long double,
1035 (const char *restrict str
, char **restrict endp
));
1037 # if !@HAVE_STRTOLD@
1038 _GL_FUNCDECL_SYS (strtold
, long double,
1039 (const char *restrict str
, char **restrict endp
)
1040 _GL_ARG_NONNULL ((1)));
1042 _GL_CXXALIAS_SYS (strtold
, long double,
1043 (const char *restrict str
, char **restrict endp
));
1045 _GL_CXXALIASWARN (strtold
);
1046 #elif defined GNULIB_POSIXCHECK
1048 # if HAVE_RAW_DECL_STRTOLD
1049 _GL_WARN_ON_USE (strtold
, "strtold is unportable - "
1050 "use gnulib module strtold for portability");
1054 #if @GNULIB_STRTOLL@
1055 /* Parse a signed integer whose textual representation starts at STRING.
1056 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1057 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1059 If ENDPTR is not NULL, the address of the first byte after the integer is
1061 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
1063 # if !@HAVE_STRTOLL@
1064 _GL_FUNCDECL_SYS (strtoll
, long long,
1065 (const char *restrict string
, char **restrict endptr
,
1067 _GL_ARG_NONNULL ((1)));
1069 _GL_CXXALIAS_SYS (strtoll
, long long,
1070 (const char *restrict string
, char **restrict endptr
,
1072 _GL_CXXALIASWARN (strtoll
);
1073 #elif defined GNULIB_POSIXCHECK
1075 # if HAVE_RAW_DECL_STRTOLL
1076 _GL_WARN_ON_USE (strtoll
, "strtoll is unportable - "
1077 "use gnulib module strtoll for portability");
1081 #if @GNULIB_STRTOULL@
1082 /* Parse an unsigned integer whose textual representation starts at STRING.
1083 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1084 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1086 If ENDPTR is not NULL, the address of the first byte after the integer is
1088 Upon overflow, the return value is ULLONG_MAX, and errno is set to
1090 # if !@HAVE_STRTOULL@
1091 _GL_FUNCDECL_SYS (strtoull
, unsigned long long,
1092 (const char *restrict string
, char **restrict endptr
,
1094 _GL_ARG_NONNULL ((1)));
1096 _GL_CXXALIAS_SYS (strtoull
, unsigned long long,
1097 (const char *restrict string
, char **restrict endptr
,
1099 _GL_CXXALIASWARN (strtoull
);
1100 #elif defined GNULIB_POSIXCHECK
1102 # if HAVE_RAW_DECL_STRTOULL
1103 _GL_WARN_ON_USE (strtoull
, "strtoull is unportable - "
1104 "use gnulib module strtoull for portability");
1108 #if @GNULIB_UNLOCKPT@
1109 /* Unlock the slave side of the pseudo-terminal whose master side is specified
1110 by FD, so that it can be opened. */
1111 # if !@HAVE_UNLOCKPT@
1112 _GL_FUNCDECL_SYS (unlockpt
, int, (int fd
));
1114 _GL_CXXALIAS_SYS (unlockpt
, int, (int fd
));
1115 _GL_CXXALIASWARN (unlockpt
);
1116 #elif defined GNULIB_POSIXCHECK
1118 # if HAVE_RAW_DECL_UNLOCKPT
1119 _GL_WARN_ON_USE (unlockpt
, "unlockpt is not portable - "
1120 "use gnulib module unlockpt for portability");
1124 #if @GNULIB_UNSETENV@
1125 /* Remove the variable NAME from the environment. */
1126 # if @REPLACE_UNSETENV@
1127 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1129 # define unsetenv rpl_unsetenv
1131 _GL_FUNCDECL_RPL (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1132 _GL_CXXALIAS_RPL (unsetenv
, int, (const char *name
));
1134 # if !@HAVE_DECL_UNSETENV@
1135 _GL_FUNCDECL_SYS (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1137 _GL_CXXALIAS_SYS (unsetenv
, int, (const char *name
));
1139 # if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
1140 _GL_CXXALIASWARN (unsetenv
);
1142 #elif defined GNULIB_POSIXCHECK
1144 # if HAVE_RAW_DECL_UNSETENV
1145 _GL_WARN_ON_USE (unsetenv
, "unsetenv is unportable - "
1146 "use gnulib module unsetenv for portability");
1150 /* Convert a wide character to a multibyte character. */
1152 # if @REPLACE_WCTOMB@
1153 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1155 # define wctomb rpl_wctomb
1157 _GL_FUNCDECL_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1158 _GL_CXXALIAS_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1160 _GL_CXXALIAS_SYS (wctomb
, int, (char *s
, wchar_t wc
));
1163 _GL_CXXALIASWARN (wctomb
);
1168 #endif /* _@GUARD_PREFIX@_STDLIB_H */
1169 #endif /* _@GUARD_PREFIX@_STDLIB_H */