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 /* Allocate memory with indefinite extent and specified alignment. */
492 #if @GNULIB_POSIX_MEMALIGN@
493 # if @REPLACE_POSIX_MEMALIGN@
494 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
495 # undef posix_memalign
496 # define posix_memalign rpl_posix_memalign
498 _GL_FUNCDECL_RPL (posix_memalign
, int,
499 (void **memptr
, size_t alignment
, size_t size
)
500 _GL_ARG_NONNULL ((1)));
501 _GL_CXXALIAS_RPL (posix_memalign
, int,
502 (void **memptr
, size_t alignment
, size_t size
));
504 # if @HAVE_POSIX_MEMALIGN@
505 _GL_CXXALIAS_SYS (posix_memalign
, int,
506 (void **memptr
, size_t alignment
, size_t size
));
509 # if @HAVE_POSIX_MEMALIGN@
510 _GL_CXXALIASWARN (posix_memalign
);
512 #elif defined GNULIB_POSIXCHECK
513 # undef posix_memalign
514 # if HAVE_RAW_DECL_POSIX_MEMALIGN
515 _GL_WARN_ON_USE (posix_memalign
, "posix_memalign is not portable - "
516 "use gnulib module posix_memalign for portability");
520 #if @GNULIB_POSIX_OPENPT@
521 /* Return an FD open to the master side of a pseudo-terminal. Flags should
522 include O_RDWR, and may also include O_NOCTTY. */
523 # if !@HAVE_POSIX_OPENPT@
524 _GL_FUNCDECL_SYS (posix_openpt
, int, (int flags
));
526 _GL_CXXALIAS_SYS (posix_openpt
, int, (int flags
));
527 _GL_CXXALIASWARN (posix_openpt
);
528 #elif defined GNULIB_POSIXCHECK
530 # if HAVE_RAW_DECL_POSIX_OPENPT
531 _GL_WARN_ON_USE (posix_openpt
, "posix_openpt is not portable - "
532 "use gnulib module posix_openpt for portability");
537 /* Return the pathname of the pseudo-terminal slave associated with
538 the master FD is open on, or NULL on errors. */
539 # if @REPLACE_PTSNAME@
540 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
542 # define ptsname rpl_ptsname
544 _GL_FUNCDECL_RPL (ptsname
, char *, (int fd
));
545 _GL_CXXALIAS_RPL (ptsname
, char *, (int fd
));
548 _GL_FUNCDECL_SYS (ptsname
, char *, (int fd
));
550 _GL_CXXALIAS_SYS (ptsname
, char *, (int fd
));
552 _GL_CXXALIASWARN (ptsname
);
553 #elif defined GNULIB_POSIXCHECK
555 # if HAVE_RAW_DECL_PTSNAME
556 _GL_WARN_ON_USE (ptsname
, "ptsname is not portable - "
557 "use gnulib module ptsname for portability");
561 #if @GNULIB_PTSNAME_R@
562 /* Set the pathname of the pseudo-terminal slave associated with
563 the master FD is open on and return 0, or set errno and return
564 non-zero on errors. */
565 # if @REPLACE_PTSNAME_R@
566 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
568 # define ptsname_r rpl_ptsname_r
570 _GL_FUNCDECL_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
571 _GL_CXXALIAS_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
573 # if !@HAVE_PTSNAME_R@
574 _GL_FUNCDECL_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
576 _GL_CXXALIAS_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
578 # ifndef GNULIB_defined_ptsname_r
579 # define GNULIB_defined_ptsname_r (!@HAVE_PTSNAME_R@ || @REPLACE_PTSNAME_R@)
581 _GL_CXXALIASWARN (ptsname_r
);
582 #elif defined GNULIB_POSIXCHECK
584 # if HAVE_RAW_DECL_PTSNAME_R
585 _GL_WARN_ON_USE (ptsname_r
, "ptsname_r is not portable - "
586 "use gnulib module ptsname_r for portability");
591 # if @REPLACE_PUTENV@
592 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
594 # define putenv rpl_putenv
596 _GL_FUNCDECL_RPL (putenv
, int, (char *string
) _GL_ARG_NONNULL ((1)));
597 _GL_CXXALIAS_RPL (putenv
, int, (char *string
));
598 # elif defined _WIN32 && !defined __CYGWIN__
599 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
601 # define putenv _putenv
603 _GL_CXXALIAS_MDA (putenv
, int, (char *string
));
605 _GL_CXXALIAS_SYS (putenv
, int, (char *string
));
607 _GL_CXXALIASWARN (putenv
);
608 #elif defined _WIN32 && !defined __CYGWIN__
610 # define putenv _putenv
614 /* Sort an array of NMEMB elements, starting at address BASE, each element
615 occupying SIZE bytes, in ascending order according to the comparison
617 # if @REPLACE_QSORT_R@
618 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
620 # define qsort_r rpl_qsort_r
622 _GL_FUNCDECL_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
623 int (*compare
) (void const *, void const *,
625 void *arg
) _GL_ARG_NONNULL ((1, 4)));
626 _GL_CXXALIAS_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
627 int (*compare
) (void const *, void const *,
632 _GL_FUNCDECL_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
633 int (*compare
) (void const *, void const *,
635 void *arg
) _GL_ARG_NONNULL ((1, 4)));
637 _GL_CXXALIAS_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
638 int (*compare
) (void const *, void const *,
642 _GL_CXXALIASWARN (qsort_r
);
643 #elif defined GNULIB_POSIXCHECK
645 # if HAVE_RAW_DECL_QSORT_R
646 _GL_WARN_ON_USE (qsort_r
, "qsort_r is not portable - "
647 "use gnulib module qsort_r for portability");
652 #if @GNULIB_RANDOM_R@
653 # if !@HAVE_RANDOM_R@
655 # define RAND_MAX 2147483647
662 # if @REPLACE_RANDOM@
663 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
665 # define random rpl_random
667 _GL_FUNCDECL_RPL (random
, long, (void));
668 _GL_CXXALIAS_RPL (random
, long, (void));
671 _GL_FUNCDECL_SYS (random
, long, (void));
673 /* Need to cast, because on Haiku, the return type is
675 _GL_CXXALIAS_SYS_CAST (random
, long, (void));
677 _GL_CXXALIASWARN (random
);
678 #elif defined GNULIB_POSIXCHECK
680 # if HAVE_RAW_DECL_RANDOM
681 _GL_WARN_ON_USE (random
, "random is unportable - "
682 "use gnulib module random for portability");
687 # if @REPLACE_RANDOM@
688 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
690 # define srandom rpl_srandom
692 _GL_FUNCDECL_RPL (srandom
, void, (unsigned int seed
));
693 _GL_CXXALIAS_RPL (srandom
, void, (unsigned int seed
));
696 _GL_FUNCDECL_SYS (srandom
, void, (unsigned int seed
));
698 /* Need to cast, because on FreeBSD, the first parameter is
699 unsigned long seed. */
700 _GL_CXXALIAS_SYS_CAST (srandom
, void, (unsigned int seed
));
702 _GL_CXXALIASWARN (srandom
);
703 #elif defined GNULIB_POSIXCHECK
705 # if HAVE_RAW_DECL_SRANDOM
706 _GL_WARN_ON_USE (srandom
, "srandom is unportable - "
707 "use gnulib module random for portability");
712 # if @REPLACE_INITSTATE@
713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715 # define initstate rpl_initstate
717 _GL_FUNCDECL_RPL (initstate
, char *,
718 (unsigned int seed
, char *buf
, size_t buf_size
)
719 _GL_ARG_NONNULL ((2)));
720 _GL_CXXALIAS_RPL (initstate
, char *,
721 (unsigned int seed
, char *buf
, size_t buf_size
));
723 # if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
724 _GL_FUNCDECL_SYS (initstate
, char *,
725 (unsigned int seed
, char *buf
, size_t buf_size
)
726 _GL_ARG_NONNULL ((2)));
728 /* Need to cast, because on FreeBSD, the first parameter is
729 unsigned long seed. */
730 _GL_CXXALIAS_SYS_CAST (initstate
, char *,
731 (unsigned int seed
, char *buf
, size_t buf_size
));
733 _GL_CXXALIASWARN (initstate
);
734 #elif defined GNULIB_POSIXCHECK
736 # if HAVE_RAW_DECL_INITSTATE
737 _GL_WARN_ON_USE (initstate
, "initstate is unportable - "
738 "use gnulib module random for portability");
743 # if @REPLACE_SETSTATE@
744 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
746 # define setstate rpl_setstate
748 _GL_FUNCDECL_RPL (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
749 _GL_CXXALIAS_RPL (setstate
, char *, (char *arg_state
));
751 # if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
752 _GL_FUNCDECL_SYS (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
754 /* Need to cast, because on Mac OS X 10.13, HP-UX, Solaris the first parameter
755 is const char *arg_state. */
756 _GL_CXXALIAS_SYS_CAST (setstate
, char *, (char *arg_state
));
758 _GL_CXXALIASWARN (setstate
);
759 #elif defined GNULIB_POSIXCHECK
761 # if HAVE_RAW_DECL_SETSTATE
762 _GL_WARN_ON_USE (setstate
, "setstate is unportable - "
763 "use gnulib module random for portability");
768 #if @GNULIB_RANDOM_R@
769 # if @REPLACE_RANDOM_R@
770 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
772 # define random_r rpl_random_r
774 _GL_FUNCDECL_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
)
775 _GL_ARG_NONNULL ((1, 2)));
776 _GL_CXXALIAS_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
));
778 # if !@HAVE_RANDOM_R@
779 _GL_FUNCDECL_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
)
780 _GL_ARG_NONNULL ((1, 2)));
782 _GL_CXXALIAS_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
));
784 _GL_CXXALIASWARN (random_r
);
785 #elif defined GNULIB_POSIXCHECK
787 # if HAVE_RAW_DECL_RANDOM_R
788 _GL_WARN_ON_USE (random_r
, "random_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 srandom_r rpl_srandom_r
799 _GL_FUNCDECL_RPL (srandom_r
, int,
800 (unsigned int seed
, struct random_data
*rand_state
)
801 _GL_ARG_NONNULL ((2)));
802 _GL_CXXALIAS_RPL (srandom_r
, int,
803 (unsigned int seed
, struct random_data
*rand_state
));
805 # if !@HAVE_RANDOM_R@
806 _GL_FUNCDECL_SYS (srandom_r
, int,
807 (unsigned int seed
, struct random_data
*rand_state
)
808 _GL_ARG_NONNULL ((2)));
810 _GL_CXXALIAS_SYS (srandom_r
, int,
811 (unsigned int seed
, struct random_data
*rand_state
));
813 _GL_CXXALIASWARN (srandom_r
);
814 #elif defined GNULIB_POSIXCHECK
816 # if HAVE_RAW_DECL_SRANDOM_R
817 _GL_WARN_ON_USE (srandom_r
, "srandom_r is unportable - "
818 "use gnulib module random_r for portability");
822 #if @GNULIB_RANDOM_R@
823 # if @REPLACE_RANDOM_R@
824 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
826 # define initstate_r rpl_initstate_r
828 _GL_FUNCDECL_RPL (initstate_r
, int,
829 (unsigned int seed
, char *buf
, size_t buf_size
,
830 struct random_data
*rand_state
)
831 _GL_ARG_NONNULL ((2, 4)));
832 _GL_CXXALIAS_RPL (initstate_r
, int,
833 (unsigned int seed
, char *buf
, size_t buf_size
,
834 struct random_data
*rand_state
));
836 # if !@HAVE_RANDOM_R@
837 _GL_FUNCDECL_SYS (initstate_r
, int,
838 (unsigned int seed
, char *buf
, size_t buf_size
,
839 struct random_data
*rand_state
)
840 _GL_ARG_NONNULL ((2, 4)));
842 /* Need to cast, because on Haiku, the third parameter is
843 unsigned long buf_size. */
844 _GL_CXXALIAS_SYS_CAST (initstate_r
, int,
845 (unsigned int seed
, char *buf
, size_t buf_size
,
846 struct random_data
*rand_state
));
848 _GL_CXXALIASWARN (initstate_r
);
849 #elif defined GNULIB_POSIXCHECK
851 # if HAVE_RAW_DECL_INITSTATE_R
852 _GL_WARN_ON_USE (initstate_r
, "initstate_r is unportable - "
853 "use gnulib module random_r for portability");
857 #if @GNULIB_RANDOM_R@
858 # if @REPLACE_RANDOM_R@
859 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
861 # define setstate_r rpl_setstate_r
863 _GL_FUNCDECL_RPL (setstate_r
, int,
864 (char *arg_state
, struct random_data
*rand_state
)
865 _GL_ARG_NONNULL ((1, 2)));
866 _GL_CXXALIAS_RPL (setstate_r
, int,
867 (char *arg_state
, struct random_data
*rand_state
));
869 # if !@HAVE_RANDOM_R@
870 _GL_FUNCDECL_SYS (setstate_r
, int,
871 (char *arg_state
, struct random_data
*rand_state
)
872 _GL_ARG_NONNULL ((1, 2)));
874 /* Need to cast, because on Haiku, the first parameter is
876 _GL_CXXALIAS_SYS_CAST (setstate_r
, int,
877 (char *arg_state
, struct random_data
*rand_state
));
879 _GL_CXXALIASWARN (setstate_r
);
880 #elif defined GNULIB_POSIXCHECK
882 # if HAVE_RAW_DECL_SETSTATE_R
883 _GL_WARN_ON_USE (setstate_r
, "setstate_r is unportable - "
884 "use gnulib module random_r for portability");
889 #if @GNULIB_REALLOC_POSIX@
890 # if @REPLACE_REALLOC@
891 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
892 || _GL_USE_STDLIB_ALLOC)
894 # define realloc rpl_realloc
896 _GL_FUNCDECL_RPL (realloc
, void *, (void *ptr
, size_t size
));
897 _GL_CXXALIAS_RPL (realloc
, void *, (void *ptr
, size_t size
));
899 _GL_CXXALIAS_SYS (realloc
, void *, (void *ptr
, size_t size
));
902 _GL_CXXALIASWARN (realloc
);
904 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
906 /* Assume realloc is always declared. */
907 _GL_WARN_ON_USE (realloc
, "realloc is not POSIX compliant everywhere - "
908 "use gnulib module realloc-posix for portability");
912 #if @GNULIB_REALLOCARRAY@
913 # if ! @HAVE_REALLOCARRAY@
914 _GL_FUNCDECL_SYS (reallocarray
, void *,
915 (void *ptr
, size_t nmemb
, size_t size
));
917 _GL_CXXALIAS_SYS (reallocarray
, void *,
918 (void *ptr
, size_t nmemb
, size_t size
));
919 _GL_CXXALIASWARN (reallocarray
);
920 #elif defined GNULIB_POSIXCHECK
922 # if HAVE_RAW_DECL_REALLOCARRAY
923 _GL_WARN_ON_USE (reallocarray
, "reallocarray is not portable - "
924 "use gnulib module reallocarray for portability");
928 #if @GNULIB_REALPATH@
929 # if @REPLACE_REALPATH@
930 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
931 # define realpath rpl_realpath
933 _GL_FUNCDECL_RPL (realpath
, char *,
934 (const char *restrict name
, char *restrict resolved
)
935 _GL_ARG_NONNULL ((1)));
936 _GL_CXXALIAS_RPL (realpath
, char *,
937 (const char *restrict name
, char *restrict resolved
));
939 # if !@HAVE_REALPATH@
940 _GL_FUNCDECL_SYS (realpath
, char *,
941 (const char *restrict name
, char *restrict resolved
)
942 _GL_ARG_NONNULL ((1)));
944 _GL_CXXALIAS_SYS (realpath
, char *,
945 (const char *restrict name
, char *restrict resolved
));
947 _GL_CXXALIASWARN (realpath
);
948 #elif defined GNULIB_POSIXCHECK
950 # if HAVE_RAW_DECL_REALPATH
951 _GL_WARN_ON_USE (realpath
, "realpath is unportable - use gnulib module "
952 "canonicalize or canonicalize-lgpl for portability");
957 /* Test a user response to a question.
958 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
960 _GL_FUNCDECL_SYS (rpmatch
, int, (const char *response
) _GL_ARG_NONNULL ((1)));
962 _GL_CXXALIAS_SYS (rpmatch
, int, (const char *response
));
963 _GL_CXXALIASWARN (rpmatch
);
964 #elif defined GNULIB_POSIXCHECK
966 # if HAVE_RAW_DECL_RPMATCH
967 _GL_WARN_ON_USE (rpmatch
, "rpmatch is unportable - "
968 "use gnulib module rpmatch for portability");
972 #if @GNULIB_SECURE_GETENV@
973 /* Look up NAME in the environment, returning 0 in insecure situations. */
974 # if !@HAVE_SECURE_GETENV@
975 _GL_FUNCDECL_SYS (secure_getenv
, char *,
976 (char const *name
) _GL_ARG_NONNULL ((1)));
978 _GL_CXXALIAS_SYS (secure_getenv
, char *, (char const *name
));
979 _GL_CXXALIASWARN (secure_getenv
);
980 #elif defined GNULIB_POSIXCHECK
981 # undef secure_getenv
982 # if HAVE_RAW_DECL_SECURE_GETENV
983 _GL_WARN_ON_USE (secure_getenv
, "secure_getenv is unportable - "
984 "use gnulib module secure_getenv for portability");
989 /* Set NAME to VALUE in the environment.
990 If REPLACE is nonzero, overwrite an existing value. */
991 # if @REPLACE_SETENV@
992 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
994 # define setenv rpl_setenv
996 _GL_FUNCDECL_RPL (setenv
, int,
997 (const char *name
, const char *value
, int replace
)
998 _GL_ARG_NONNULL ((1)));
999 _GL_CXXALIAS_RPL (setenv
, int,
1000 (const char *name
, const char *value
, int replace
));
1002 # if !@HAVE_DECL_SETENV@
1003 _GL_FUNCDECL_SYS (setenv
, int,
1004 (const char *name
, const char *value
, int replace
)
1005 _GL_ARG_NONNULL ((1)));
1007 _GL_CXXALIAS_SYS (setenv
, int,
1008 (const char *name
, const char *value
, int replace
));
1010 # if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
1011 _GL_CXXALIASWARN (setenv
);
1013 #elif defined GNULIB_POSIXCHECK
1015 # if HAVE_RAW_DECL_SETENV
1016 _GL_WARN_ON_USE (setenv
, "setenv is unportable - "
1017 "use gnulib module setenv for portability");
1022 /* Parse a double from STRING, updating ENDP if appropriate. */
1023 # if @REPLACE_STRTOD@
1024 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1025 # define strtod rpl_strtod
1027 # define GNULIB_defined_strtod_function 1
1028 _GL_FUNCDECL_RPL (strtod
, double,
1029 (const char *restrict str
, char **restrict endp
)
1030 _GL_ARG_NONNULL ((1)));
1031 _GL_CXXALIAS_RPL (strtod
, double,
1032 (const char *restrict str
, char **restrict endp
));
1035 _GL_FUNCDECL_SYS (strtod
, double,
1036 (const char *restrict str
, char **restrict endp
)
1037 _GL_ARG_NONNULL ((1)));
1039 _GL_CXXALIAS_SYS (strtod
, double,
1040 (const char *restrict str
, char **restrict endp
));
1043 _GL_CXXALIASWARN (strtod
);
1045 #elif defined GNULIB_POSIXCHECK
1047 # if HAVE_RAW_DECL_STRTOD
1048 _GL_WARN_ON_USE (strtod
, "strtod is unportable - "
1049 "use gnulib module strtod for portability");
1053 #if @GNULIB_STRTOLD@
1054 /* Parse a 'long double' from STRING, updating ENDP if appropriate. */
1055 # if @REPLACE_STRTOLD@
1056 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1057 # define strtold rpl_strtold
1059 # define GNULIB_defined_strtold_function 1
1060 _GL_FUNCDECL_RPL (strtold
, long double,
1061 (const char *restrict str
, char **restrict endp
)
1062 _GL_ARG_NONNULL ((1)));
1063 _GL_CXXALIAS_RPL (strtold
, long double,
1064 (const char *restrict str
, char **restrict endp
));
1066 # if !@HAVE_STRTOLD@
1067 _GL_FUNCDECL_SYS (strtold
, long double,
1068 (const char *restrict str
, char **restrict endp
)
1069 _GL_ARG_NONNULL ((1)));
1071 _GL_CXXALIAS_SYS (strtold
, long double,
1072 (const char *restrict str
, char **restrict endp
));
1074 _GL_CXXALIASWARN (strtold
);
1075 #elif defined GNULIB_POSIXCHECK
1077 # if HAVE_RAW_DECL_STRTOLD
1078 _GL_WARN_ON_USE (strtold
, "strtold is unportable - "
1079 "use gnulib module strtold for portability");
1083 #if @GNULIB_STRTOLL@
1084 /* Parse a signed integer whose textual representation starts at STRING.
1085 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1086 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1088 If ENDPTR is not NULL, the address of the first byte after the integer is
1090 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
1092 # if !@HAVE_STRTOLL@
1093 _GL_FUNCDECL_SYS (strtoll
, long long,
1094 (const char *restrict string
, char **restrict endptr
,
1096 _GL_ARG_NONNULL ((1)));
1098 _GL_CXXALIAS_SYS (strtoll
, long long,
1099 (const char *restrict string
, char **restrict endptr
,
1101 _GL_CXXALIASWARN (strtoll
);
1102 #elif defined GNULIB_POSIXCHECK
1104 # if HAVE_RAW_DECL_STRTOLL
1105 _GL_WARN_ON_USE (strtoll
, "strtoll is unportable - "
1106 "use gnulib module strtoll for portability");
1110 #if @GNULIB_STRTOULL@
1111 /* Parse an unsigned integer whose textual representation starts at STRING.
1112 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1113 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1115 If ENDPTR is not NULL, the address of the first byte after the integer is
1117 Upon overflow, the return value is ULLONG_MAX, and errno is set to
1119 # if !@HAVE_STRTOULL@
1120 _GL_FUNCDECL_SYS (strtoull
, unsigned long long,
1121 (const char *restrict string
, char **restrict endptr
,
1123 _GL_ARG_NONNULL ((1)));
1125 _GL_CXXALIAS_SYS (strtoull
, unsigned long long,
1126 (const char *restrict string
, char **restrict endptr
,
1128 _GL_CXXALIASWARN (strtoull
);
1129 #elif defined GNULIB_POSIXCHECK
1131 # if HAVE_RAW_DECL_STRTOULL
1132 _GL_WARN_ON_USE (strtoull
, "strtoull is unportable - "
1133 "use gnulib module strtoull for portability");
1137 #if @GNULIB_UNLOCKPT@
1138 /* Unlock the slave side of the pseudo-terminal whose master side is specified
1139 by FD, so that it can be opened. */
1140 # if !@HAVE_UNLOCKPT@
1141 _GL_FUNCDECL_SYS (unlockpt
, int, (int fd
));
1143 _GL_CXXALIAS_SYS (unlockpt
, int, (int fd
));
1144 _GL_CXXALIASWARN (unlockpt
);
1145 #elif defined GNULIB_POSIXCHECK
1147 # if HAVE_RAW_DECL_UNLOCKPT
1148 _GL_WARN_ON_USE (unlockpt
, "unlockpt is not portable - "
1149 "use gnulib module unlockpt for portability");
1153 #if @GNULIB_UNSETENV@
1154 /* Remove the variable NAME from the environment. */
1155 # if @REPLACE_UNSETENV@
1156 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1158 # define unsetenv rpl_unsetenv
1160 _GL_FUNCDECL_RPL (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1161 _GL_CXXALIAS_RPL (unsetenv
, int, (const char *name
));
1163 # if !@HAVE_DECL_UNSETENV@
1164 _GL_FUNCDECL_SYS (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1166 _GL_CXXALIAS_SYS (unsetenv
, int, (const char *name
));
1168 # if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
1169 _GL_CXXALIASWARN (unsetenv
);
1171 #elif defined GNULIB_POSIXCHECK
1173 # if HAVE_RAW_DECL_UNSETENV
1174 _GL_WARN_ON_USE (unsetenv
, "unsetenv is unportable - "
1175 "use gnulib module unsetenv for portability");
1179 /* Convert a wide character to a multibyte character. */
1181 # if @REPLACE_WCTOMB@
1182 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1184 # define wctomb rpl_wctomb
1186 _GL_FUNCDECL_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1187 _GL_CXXALIAS_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1189 _GL_CXXALIAS_SYS (wctomb
, int, (char *s
, wchar_t wc
));
1192 _GL_CXXALIASWARN (wctomb
);
1197 #endif /* _@GUARD_PREFIX@_STDLIB_H */
1198 #endif /* _@GUARD_PREFIX@_STDLIB_H */