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 @GNULIB_GETLOADAVG@
221 /* Store max(NELEM,3) load average numbers in LOADAVG[].
222 The three numbers are the load average of the last 1 minute, the last 5
223 minutes, and the last 15 minutes, respectively.
224 LOADAVG is an array of NELEM numbers. */
225 # if !@HAVE_DECL_GETLOADAVG@
226 _GL_FUNCDECL_SYS (getloadavg
, int, (double loadavg
[], int nelem
)
227 _GL_ARG_NONNULL ((1)));
229 _GL_CXXALIAS_SYS (getloadavg
, int, (double loadavg
[], int nelem
));
230 _GL_CXXALIASWARN (getloadavg
);
231 #elif defined GNULIB_POSIXCHECK
233 # if HAVE_RAW_DECL_GETLOADAVG
234 _GL_WARN_ON_USE (getloadavg
, "getloadavg is not portable - "
235 "use gnulib module getloadavg for portability");
239 #if @GNULIB_GETSUBOPT@
240 /* Assuming *OPTIONP is a comma separated list of elements of the form
241 "token" or "token=value", getsubopt parses the first of these elements.
242 If the first element refers to a "token" that is member of the given
243 NULL-terminated array of tokens:
244 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
245 the first option and the comma, sets *VALUEP to the value of the
246 element (or NULL if it doesn't contain an "=" sign),
247 - It returns the index of the "token" in the given array of tokens.
248 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
249 For more details see the POSIX specification.
250 https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsubopt.html */
251 # if !@HAVE_GETSUBOPT@
252 _GL_FUNCDECL_SYS (getsubopt
, int,
253 (char **optionp
, char *const *tokens
, char **valuep
)
254 _GL_ARG_NONNULL ((1, 2, 3)));
256 _GL_CXXALIAS_SYS (getsubopt
, int,
257 (char **optionp
, char *const *tokens
, char **valuep
));
258 _GL_CXXALIASWARN (getsubopt
);
259 #elif defined GNULIB_POSIXCHECK
261 # if HAVE_RAW_DECL_GETSUBOPT
262 _GL_WARN_ON_USE (getsubopt
, "getsubopt is unportable - "
263 "use gnulib module getsubopt for portability");
268 /* Change the ownership and access permission of the slave side of the
269 pseudo-terminal whose master side is specified by FD. */
271 _GL_FUNCDECL_SYS (grantpt
, int, (int fd
));
273 _GL_CXXALIAS_SYS (grantpt
, int, (int fd
));
274 _GL_CXXALIASWARN (grantpt
);
275 #elif defined GNULIB_POSIXCHECK
277 # if HAVE_RAW_DECL_GRANTPT
278 _GL_WARN_ON_USE (grantpt
, "grantpt is not portable - "
279 "use gnulib module grantpt for portability");
283 /* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
284 rely on GNU or POSIX semantics for malloc and realloc (for example,
285 by never specifying a zero size), so it does not need malloc or
286 realloc to be redefined. */
287 #if @GNULIB_MALLOC_POSIX@
288 # if @REPLACE_MALLOC@
289 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
290 || _GL_USE_STDLIB_ALLOC)
292 # define malloc rpl_malloc
294 _GL_FUNCDECL_RPL (malloc
, void *, (size_t size
));
295 _GL_CXXALIAS_RPL (malloc
, void *, (size_t size
));
297 _GL_CXXALIAS_SYS (malloc
, void *, (size_t size
));
300 _GL_CXXALIASWARN (malloc
);
302 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
304 /* Assume malloc is always declared. */
305 _GL_WARN_ON_USE (malloc
, "malloc is not POSIX compliant everywhere - "
306 "use gnulib module malloc-posix for portability");
309 /* Convert a multibyte character to a wide character. */
311 # if @REPLACE_MBTOWC@
312 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
314 # define mbtowc rpl_mbtowc
316 _GL_FUNCDECL_RPL (mbtowc
, int,
317 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
318 _GL_CXXALIAS_RPL (mbtowc
, int,
319 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
322 _GL_FUNCDECL_SYS (mbtowc
, int,
323 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
325 _GL_CXXALIAS_SYS (mbtowc
, int,
326 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
));
329 _GL_CXXALIASWARN (mbtowc
);
331 #elif defined GNULIB_POSIXCHECK
333 # if HAVE_RAW_DECL_MBTOWC
334 _GL_WARN_ON_USE (mbtowc
, "mbtowc is not portable - "
335 "use gnulib module mbtowc for portability");
340 /* Create a unique temporary directory from TEMPLATE.
341 The last six characters of TEMPLATE must be "XXXXXX";
342 they are replaced with a string that makes the directory name unique.
343 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
344 The directory is created mode 700. */
346 _GL_FUNCDECL_SYS (mkdtemp
, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
348 _GL_CXXALIAS_SYS (mkdtemp
, char *, (char * /*template*/));
349 _GL_CXXALIASWARN (mkdtemp
);
350 #elif defined GNULIB_POSIXCHECK
352 # if HAVE_RAW_DECL_MKDTEMP
353 _GL_WARN_ON_USE (mkdtemp
, "mkdtemp is unportable - "
354 "use gnulib module mkdtemp for portability");
358 #if @GNULIB_MKOSTEMP@
359 /* Create a unique temporary file from TEMPLATE.
360 The last six characters of TEMPLATE must be "XXXXXX";
361 they are replaced with a string that makes the file name unique.
362 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
363 and O_TEXT, O_BINARY (defined in "binary-io.h").
364 The file is then created, with the specified flags, ensuring it didn't exist
366 The file is created read-write (mask at least 0600 & ~umask), but it may be
367 world-readable and world-writable (mask 0666 & ~umask), depending on the
369 Returns the open file descriptor if successful, otherwise -1 and errno
371 # if !@HAVE_MKOSTEMP@
372 _GL_FUNCDECL_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/)
373 _GL_ARG_NONNULL ((1)));
375 _GL_CXXALIAS_SYS (mkostemp
, int, (char * /*template*/, int /*flags*/));
376 _GL_CXXALIASWARN (mkostemp
);
377 #elif defined GNULIB_POSIXCHECK
379 # if HAVE_RAW_DECL_MKOSTEMP
380 _GL_WARN_ON_USE (mkostemp
, "mkostemp is unportable - "
381 "use gnulib module mkostemp for portability");
385 #if @GNULIB_MKOSTEMPS@
386 /* Create a unique temporary file from TEMPLATE.
387 The last six characters of TEMPLATE before a suffix of length
388 SUFFIXLEN must be "XXXXXX";
389 they are replaced with a string that makes the file name unique.
390 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
391 and O_TEXT, O_BINARY (defined in "binary-io.h").
392 The file is then created, with the specified flags, ensuring it didn't exist
394 The file is created read-write (mask at least 0600 & ~umask), but it may be
395 world-readable and world-writable (mask 0666 & ~umask), depending on the
397 Returns the open file descriptor if successful, otherwise -1 and errno
399 # if !@HAVE_MKOSTEMPS@
400 _GL_FUNCDECL_SYS (mkostemps
, int,
401 (char * /*template*/, int /*suffixlen*/, int /*flags*/)
402 _GL_ARG_NONNULL ((1)));
404 _GL_CXXALIAS_SYS (mkostemps
, int,
405 (char * /*template*/, int /*suffixlen*/, int /*flags*/));
406 _GL_CXXALIASWARN (mkostemps
);
407 #elif defined GNULIB_POSIXCHECK
409 # if HAVE_RAW_DECL_MKOSTEMPS
410 _GL_WARN_ON_USE (mkostemps
, "mkostemps is unportable - "
411 "use gnulib module mkostemps for portability");
416 /* Create a unique temporary file from TEMPLATE.
417 The last six characters of TEMPLATE must be "XXXXXX";
418 they are replaced with a string that makes the file name unique.
419 The file is then created, ensuring it didn't exist before.
420 The file is created read-write (mask at least 0600 & ~umask), but it may be
421 world-readable and world-writable (mask 0666 & ~umask), depending on the
423 Returns the open file descriptor if successful, otherwise -1 and errno
425 # if @REPLACE_MKSTEMP@
426 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
427 # define mkstemp rpl_mkstemp
429 _GL_FUNCDECL_RPL (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
430 _GL_CXXALIAS_RPL (mkstemp
, int, (char * /*template*/));
432 # if ! @HAVE_MKSTEMP@
433 _GL_FUNCDECL_SYS (mkstemp
, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
435 _GL_CXXALIAS_SYS (mkstemp
, int, (char * /*template*/));
437 _GL_CXXALIASWARN (mkstemp
);
438 #elif defined GNULIB_POSIXCHECK
440 # if HAVE_RAW_DECL_MKSTEMP
441 _GL_WARN_ON_USE (mkstemp
, "mkstemp is unportable - "
442 "use gnulib module mkstemp for portability");
446 #if @GNULIB_MKSTEMPS@
447 /* Create a unique temporary file from TEMPLATE.
448 The last six characters of TEMPLATE prior to a suffix of length
449 SUFFIXLEN must be "XXXXXX";
450 they are replaced with a string that makes the file name unique.
451 The file is then created, ensuring it didn't exist before.
452 The file is created read-write (mask at least 0600 & ~umask), but it may be
453 world-readable and world-writable (mask 0666 & ~umask), depending on the
455 Returns the open file descriptor if successful, otherwise -1 and errno
457 # if !@HAVE_MKSTEMPS@
458 _GL_FUNCDECL_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/)
459 _GL_ARG_NONNULL ((1)));
461 _GL_CXXALIAS_SYS (mkstemps
, int, (char * /*template*/, int /*suffixlen*/));
462 _GL_CXXALIASWARN (mkstemps
);
463 #elif defined GNULIB_POSIXCHECK
465 # if HAVE_RAW_DECL_MKSTEMPS
466 _GL_WARN_ON_USE (mkstemps
, "mkstemps is unportable - "
467 "use gnulib module mkstemps for portability");
471 #if @GNULIB_POSIX_OPENPT@
472 /* Return an FD open to the master side of a pseudo-terminal. Flags should
473 include O_RDWR, and may also include O_NOCTTY. */
474 # if !@HAVE_POSIX_OPENPT@
475 _GL_FUNCDECL_SYS (posix_openpt
, int, (int flags
));
477 _GL_CXXALIAS_SYS (posix_openpt
, int, (int flags
));
478 _GL_CXXALIASWARN (posix_openpt
);
479 #elif defined GNULIB_POSIXCHECK
481 # if HAVE_RAW_DECL_POSIX_OPENPT
482 _GL_WARN_ON_USE (posix_openpt
, "posix_openpt is not portable - "
483 "use gnulib module posix_openpt for portability");
488 /* Return the pathname of the pseudo-terminal slave associated with
489 the master FD is open on, or NULL on errors. */
490 # if @REPLACE_PTSNAME@
491 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
493 # define ptsname rpl_ptsname
495 _GL_FUNCDECL_RPL (ptsname
, char *, (int fd
));
496 _GL_CXXALIAS_RPL (ptsname
, char *, (int fd
));
499 _GL_FUNCDECL_SYS (ptsname
, char *, (int fd
));
501 _GL_CXXALIAS_SYS (ptsname
, char *, (int fd
));
503 _GL_CXXALIASWARN (ptsname
);
504 #elif defined GNULIB_POSIXCHECK
506 # if HAVE_RAW_DECL_PTSNAME
507 _GL_WARN_ON_USE (ptsname
, "ptsname is not portable - "
508 "use gnulib module ptsname for portability");
512 #if @GNULIB_PTSNAME_R@
513 /* Set the pathname of the pseudo-terminal slave associated with
514 the master FD is open on and return 0, or set errno and return
515 non-zero on errors. */
516 # if @REPLACE_PTSNAME_R@
517 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
519 # define ptsname_r rpl_ptsname_r
521 _GL_FUNCDECL_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
522 _GL_CXXALIAS_RPL (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
524 # if !@HAVE_PTSNAME_R@
525 _GL_FUNCDECL_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
527 _GL_CXXALIAS_SYS (ptsname_r
, int, (int fd
, char *buf
, size_t len
));
529 # ifndef GNULIB_defined_ptsname_r
530 # define GNULIB_defined_ptsname_r (!@HAVE_PTSNAME_R@ || @REPLACE_PTSNAME_R@)
532 _GL_CXXALIASWARN (ptsname_r
);
533 #elif defined GNULIB_POSIXCHECK
535 # if HAVE_RAW_DECL_PTSNAME_R
536 _GL_WARN_ON_USE (ptsname_r
, "ptsname_r is not portable - "
537 "use gnulib module ptsname_r for portability");
542 # if @REPLACE_PUTENV@
543 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
545 # define putenv rpl_putenv
547 _GL_FUNCDECL_RPL (putenv
, int, (char *string
) _GL_ARG_NONNULL ((1)));
548 _GL_CXXALIAS_RPL (putenv
, int, (char *string
));
550 _GL_CXXALIAS_SYS (putenv
, int, (char *string
));
552 _GL_CXXALIASWARN (putenv
);
556 /* Sort an array of NMEMB elements, starting at address BASE, each element
557 occupying SIZE bytes, in ascending order according to the comparison
559 # if @REPLACE_QSORT_R@
560 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
562 # define qsort_r rpl_qsort_r
564 _GL_FUNCDECL_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
565 int (*compare
) (void const *, void const *,
567 void *arg
) _GL_ARG_NONNULL ((1, 4)));
568 _GL_CXXALIAS_RPL (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
569 int (*compare
) (void const *, void const *,
574 _GL_FUNCDECL_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
575 int (*compare
) (void const *, void const *,
577 void *arg
) _GL_ARG_NONNULL ((1, 4)));
579 _GL_CXXALIAS_SYS (qsort_r
, void, (void *base
, size_t nmemb
, size_t size
,
580 int (*compare
) (void const *, void const *,
584 _GL_CXXALIASWARN (qsort_r
);
585 #elif defined GNULIB_POSIXCHECK
587 # if HAVE_RAW_DECL_QSORT_R
588 _GL_WARN_ON_USE (qsort_r
, "qsort_r is not portable - "
589 "use gnulib module qsort_r for portability");
594 #if @GNULIB_RANDOM_R@
595 # if !@HAVE_RANDOM_R@
597 # define RAND_MAX 2147483647
604 # if @REPLACE_RANDOM@
605 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
607 # define random rpl_random
609 _GL_FUNCDECL_RPL (random
, long, (void));
610 _GL_CXXALIAS_RPL (random
, long, (void));
613 _GL_FUNCDECL_SYS (random
, long, (void));
615 /* Need to cast, because on Haiku, the return type is
617 _GL_CXXALIAS_SYS_CAST (random
, long, (void));
619 _GL_CXXALIASWARN (random
);
620 #elif defined GNULIB_POSIXCHECK
622 # if HAVE_RAW_DECL_RANDOM
623 _GL_WARN_ON_USE (random
, "random is unportable - "
624 "use gnulib module random for portability");
629 # if @REPLACE_RANDOM@
630 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
632 # define srandom rpl_srandom
634 _GL_FUNCDECL_RPL (srandom
, void, (unsigned int seed
));
635 _GL_CXXALIAS_RPL (srandom
, void, (unsigned int seed
));
638 _GL_FUNCDECL_SYS (srandom
, void, (unsigned int seed
));
640 /* Need to cast, because on FreeBSD, the first parameter is
641 unsigned long seed. */
642 _GL_CXXALIAS_SYS_CAST (srandom
, void, (unsigned int seed
));
644 _GL_CXXALIASWARN (srandom
);
645 #elif defined GNULIB_POSIXCHECK
647 # if HAVE_RAW_DECL_SRANDOM
648 _GL_WARN_ON_USE (srandom
, "srandom is unportable - "
649 "use gnulib module random for portability");
654 # if @REPLACE_INITSTATE@
655 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
657 # define initstate rpl_initstate
659 _GL_FUNCDECL_RPL (initstate
, char *,
660 (unsigned int seed
, char *buf
, size_t buf_size
)
661 _GL_ARG_NONNULL ((2)));
662 _GL_CXXALIAS_RPL (initstate
, char *,
663 (unsigned int seed
, char *buf
, size_t buf_size
));
665 # if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
666 _GL_FUNCDECL_SYS (initstate
, char *,
667 (unsigned int seed
, char *buf
, size_t buf_size
)
668 _GL_ARG_NONNULL ((2)));
670 /* Need to cast, because on FreeBSD, the first parameter is
671 unsigned long seed. */
672 _GL_CXXALIAS_SYS_CAST (initstate
, char *,
673 (unsigned int seed
, char *buf
, size_t buf_size
));
675 _GL_CXXALIASWARN (initstate
);
676 #elif defined GNULIB_POSIXCHECK
678 # if HAVE_RAW_DECL_INITSTATE
679 _GL_WARN_ON_USE (initstate
, "initstate is unportable - "
680 "use gnulib module random for portability");
685 # if @REPLACE_SETSTATE@
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
688 # define setstate rpl_setstate
690 _GL_FUNCDECL_RPL (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
691 _GL_CXXALIAS_RPL (setstate
, char *, (char *arg_state
));
693 # if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
694 _GL_FUNCDECL_SYS (setstate
, char *, (char *arg_state
) _GL_ARG_NONNULL ((1)));
696 /* Need to cast, because on Mac OS X 10.13, HP-UX, Solaris the first parameter
697 is const char *arg_state. */
698 _GL_CXXALIAS_SYS_CAST (setstate
, char *, (char *arg_state
));
700 _GL_CXXALIASWARN (setstate
);
701 #elif defined GNULIB_POSIXCHECK
703 # if HAVE_RAW_DECL_SETSTATE
704 _GL_WARN_ON_USE (setstate
, "setstate is unportable - "
705 "use gnulib module random for portability");
710 #if @GNULIB_RANDOM_R@
711 # if @REPLACE_RANDOM_R@
712 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714 # define random_r rpl_random_r
716 _GL_FUNCDECL_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
)
717 _GL_ARG_NONNULL ((1, 2)));
718 _GL_CXXALIAS_RPL (random_r
, int, (struct random_data
*buf
, int32_t *result
));
720 # if !@HAVE_RANDOM_R@
721 _GL_FUNCDECL_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
)
722 _GL_ARG_NONNULL ((1, 2)));
724 _GL_CXXALIAS_SYS (random_r
, int, (struct random_data
*buf
, int32_t *result
));
726 _GL_CXXALIASWARN (random_r
);
727 #elif defined GNULIB_POSIXCHECK
729 # if HAVE_RAW_DECL_RANDOM_R
730 _GL_WARN_ON_USE (random_r
, "random_r is unportable - "
731 "use gnulib module random_r for portability");
735 #if @GNULIB_RANDOM_R@
736 # if @REPLACE_RANDOM_R@
737 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
739 # define srandom_r rpl_srandom_r
741 _GL_FUNCDECL_RPL (srandom_r
, int,
742 (unsigned int seed
, struct random_data
*rand_state
)
743 _GL_ARG_NONNULL ((2)));
744 _GL_CXXALIAS_RPL (srandom_r
, int,
745 (unsigned int seed
, struct random_data
*rand_state
));
747 # if !@HAVE_RANDOM_R@
748 _GL_FUNCDECL_SYS (srandom_r
, int,
749 (unsigned int seed
, struct random_data
*rand_state
)
750 _GL_ARG_NONNULL ((2)));
752 _GL_CXXALIAS_SYS (srandom_r
, int,
753 (unsigned int seed
, struct random_data
*rand_state
));
755 _GL_CXXALIASWARN (srandom_r
);
756 #elif defined GNULIB_POSIXCHECK
758 # if HAVE_RAW_DECL_SRANDOM_R
759 _GL_WARN_ON_USE (srandom_r
, "srandom_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 initstate_r rpl_initstate_r
770 _GL_FUNCDECL_RPL (initstate_r
, int,
771 (unsigned int seed
, char *buf
, size_t buf_size
,
772 struct random_data
*rand_state
)
773 _GL_ARG_NONNULL ((2, 4)));
774 _GL_CXXALIAS_RPL (initstate_r
, int,
775 (unsigned int seed
, char *buf
, size_t buf_size
,
776 struct random_data
*rand_state
));
778 # if !@HAVE_RANDOM_R@
779 _GL_FUNCDECL_SYS (initstate_r
, int,
780 (unsigned int seed
, char *buf
, size_t buf_size
,
781 struct random_data
*rand_state
)
782 _GL_ARG_NONNULL ((2, 4)));
784 /* Need to cast, because on Haiku, the third parameter is
785 unsigned long buf_size. */
786 _GL_CXXALIAS_SYS_CAST (initstate_r
, int,
787 (unsigned int seed
, char *buf
, size_t buf_size
,
788 struct random_data
*rand_state
));
790 _GL_CXXALIASWARN (initstate_r
);
791 #elif defined GNULIB_POSIXCHECK
793 # if HAVE_RAW_DECL_INITSTATE_R
794 _GL_WARN_ON_USE (initstate_r
, "initstate_r is unportable - "
795 "use gnulib module random_r for portability");
799 #if @GNULIB_RANDOM_R@
800 # if @REPLACE_RANDOM_R@
801 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
803 # define setstate_r rpl_setstate_r
805 _GL_FUNCDECL_RPL (setstate_r
, int,
806 (char *arg_state
, struct random_data
*rand_state
)
807 _GL_ARG_NONNULL ((1, 2)));
808 _GL_CXXALIAS_RPL (setstate_r
, int,
809 (char *arg_state
, struct random_data
*rand_state
));
811 # if !@HAVE_RANDOM_R@
812 _GL_FUNCDECL_SYS (setstate_r
, int,
813 (char *arg_state
, struct random_data
*rand_state
)
814 _GL_ARG_NONNULL ((1, 2)));
816 /* Need to cast, because on Haiku, the first parameter is
818 _GL_CXXALIAS_SYS_CAST (setstate_r
, int,
819 (char *arg_state
, struct random_data
*rand_state
));
821 _GL_CXXALIASWARN (setstate_r
);
822 #elif defined GNULIB_POSIXCHECK
824 # if HAVE_RAW_DECL_SETSTATE_R
825 _GL_WARN_ON_USE (setstate_r
, "setstate_r is unportable - "
826 "use gnulib module random_r for portability");
831 #if @GNULIB_REALLOC_POSIX@
832 # if @REPLACE_REALLOC@
833 # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
834 || _GL_USE_STDLIB_ALLOC)
836 # define realloc rpl_realloc
838 _GL_FUNCDECL_RPL (realloc
, void *, (void *ptr
, size_t size
));
839 _GL_CXXALIAS_RPL (realloc
, void *, (void *ptr
, size_t size
));
841 _GL_CXXALIAS_SYS (realloc
, void *, (void *ptr
, size_t size
));
844 _GL_CXXALIASWARN (realloc
);
846 #elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
848 /* Assume realloc is always declared. */
849 _GL_WARN_ON_USE (realloc
, "realloc is not POSIX compliant everywhere - "
850 "use gnulib module realloc-posix for portability");
854 #if @GNULIB_REALLOCARRAY@
855 # if ! @HAVE_REALLOCARRAY@
856 _GL_FUNCDECL_SYS (reallocarray
, void *,
857 (void *ptr
, size_t nmemb
, size_t size
));
859 _GL_CXXALIAS_SYS (reallocarray
, void *,
860 (void *ptr
, size_t nmemb
, size_t size
));
861 _GL_CXXALIASWARN (reallocarray
);
862 #elif defined GNULIB_POSIXCHECK
864 # if HAVE_RAW_DECL_REALLOCARRAY
865 _GL_WARN_ON_USE (reallocarray
, "reallocarray is not portable - "
866 "use gnulib module reallocarray for portability");
870 #if @GNULIB_REALPATH@
871 # if @REPLACE_REALPATH@
872 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
873 # define realpath rpl_realpath
875 _GL_FUNCDECL_RPL (realpath
, char *,
876 (const char *restrict name
, char *restrict resolved
)
877 _GL_ARG_NONNULL ((1)));
878 _GL_CXXALIAS_RPL (realpath
, char *,
879 (const char *restrict name
, char *restrict resolved
));
881 # if !@HAVE_REALPATH@
882 _GL_FUNCDECL_SYS (realpath
, char *,
883 (const char *restrict name
, char *restrict resolved
)
884 _GL_ARG_NONNULL ((1)));
886 _GL_CXXALIAS_SYS (realpath
, char *,
887 (const char *restrict name
, char *restrict resolved
));
889 _GL_CXXALIASWARN (realpath
);
890 #elif defined GNULIB_POSIXCHECK
892 # if HAVE_RAW_DECL_REALPATH
893 _GL_WARN_ON_USE (realpath
, "realpath is unportable - use gnulib module "
894 "canonicalize or canonicalize-lgpl for portability");
899 /* Test a user response to a question.
900 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
902 _GL_FUNCDECL_SYS (rpmatch
, int, (const char *response
) _GL_ARG_NONNULL ((1)));
904 _GL_CXXALIAS_SYS (rpmatch
, int, (const char *response
));
905 _GL_CXXALIASWARN (rpmatch
);
906 #elif defined GNULIB_POSIXCHECK
908 # if HAVE_RAW_DECL_RPMATCH
909 _GL_WARN_ON_USE (rpmatch
, "rpmatch is unportable - "
910 "use gnulib module rpmatch for portability");
914 #if @GNULIB_SECURE_GETENV@
915 /* Look up NAME in the environment, returning 0 in insecure situations. */
916 # if !@HAVE_SECURE_GETENV@
917 _GL_FUNCDECL_SYS (secure_getenv
, char *,
918 (char const *name
) _GL_ARG_NONNULL ((1)));
920 _GL_CXXALIAS_SYS (secure_getenv
, char *, (char const *name
));
921 _GL_CXXALIASWARN (secure_getenv
);
922 #elif defined GNULIB_POSIXCHECK
923 # undef secure_getenv
924 # if HAVE_RAW_DECL_SECURE_GETENV
925 _GL_WARN_ON_USE (secure_getenv
, "secure_getenv is unportable - "
926 "use gnulib module secure_getenv for portability");
931 /* Set NAME to VALUE in the environment.
932 If REPLACE is nonzero, overwrite an existing value. */
933 # if @REPLACE_SETENV@
934 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
936 # define setenv rpl_setenv
938 _GL_FUNCDECL_RPL (setenv
, int,
939 (const char *name
, const char *value
, int replace
)
940 _GL_ARG_NONNULL ((1)));
941 _GL_CXXALIAS_RPL (setenv
, int,
942 (const char *name
, const char *value
, int replace
));
944 # if !@HAVE_DECL_SETENV@
945 _GL_FUNCDECL_SYS (setenv
, int,
946 (const char *name
, const char *value
, int replace
)
947 _GL_ARG_NONNULL ((1)));
949 _GL_CXXALIAS_SYS (setenv
, int,
950 (const char *name
, const char *value
, int replace
));
952 # if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
953 _GL_CXXALIASWARN (setenv
);
955 #elif defined GNULIB_POSIXCHECK
957 # if HAVE_RAW_DECL_SETENV
958 _GL_WARN_ON_USE (setenv
, "setenv is unportable - "
959 "use gnulib module setenv for portability");
964 /* Parse a double from STRING, updating ENDP if appropriate. */
965 # if @REPLACE_STRTOD@
966 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
967 # define strtod rpl_strtod
969 # define GNULIB_defined_strtod_function 1
970 _GL_FUNCDECL_RPL (strtod
, double,
971 (const char *restrict str
, char **restrict endp
)
972 _GL_ARG_NONNULL ((1)));
973 _GL_CXXALIAS_RPL (strtod
, double,
974 (const char *restrict str
, char **restrict endp
));
977 _GL_FUNCDECL_SYS (strtod
, double,
978 (const char *restrict str
, char **restrict endp
)
979 _GL_ARG_NONNULL ((1)));
981 _GL_CXXALIAS_SYS (strtod
, double,
982 (const char *restrict str
, char **restrict endp
));
985 _GL_CXXALIASWARN (strtod
);
987 #elif defined GNULIB_POSIXCHECK
989 # if HAVE_RAW_DECL_STRTOD
990 _GL_WARN_ON_USE (strtod
, "strtod is unportable - "
991 "use gnulib module strtod for portability");
996 /* Parse a 'long double' from STRING, updating ENDP if appropriate. */
997 # if @REPLACE_STRTOLD@
998 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
999 # define strtold rpl_strtold
1001 # define GNULIB_defined_strtold_function 1
1002 _GL_FUNCDECL_RPL (strtold
, long double,
1003 (const char *restrict str
, char **restrict endp
)
1004 _GL_ARG_NONNULL ((1)));
1005 _GL_CXXALIAS_RPL (strtold
, long double,
1006 (const char *restrict str
, char **restrict endp
));
1008 # if !@HAVE_STRTOLD@
1009 _GL_FUNCDECL_SYS (strtold
, long double,
1010 (const char *restrict str
, char **restrict endp
)
1011 _GL_ARG_NONNULL ((1)));
1013 _GL_CXXALIAS_SYS (strtold
, long double,
1014 (const char *restrict str
, char **restrict endp
));
1016 _GL_CXXALIASWARN (strtold
);
1017 #elif defined GNULIB_POSIXCHECK
1019 # if HAVE_RAW_DECL_STRTOLD
1020 _GL_WARN_ON_USE (strtold
, "strtold is unportable - "
1021 "use gnulib module strtold for portability");
1025 #if @GNULIB_STRTOLL@
1026 /* Parse a signed integer whose textual representation starts at STRING.
1027 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1028 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1030 If ENDPTR is not NULL, the address of the first byte after the integer is
1032 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
1034 # if !@HAVE_STRTOLL@
1035 _GL_FUNCDECL_SYS (strtoll
, long long,
1036 (const char *restrict string
, char **restrict endptr
,
1038 _GL_ARG_NONNULL ((1)));
1040 _GL_CXXALIAS_SYS (strtoll
, long long,
1041 (const char *restrict string
, char **restrict endptr
,
1043 _GL_CXXALIASWARN (strtoll
);
1044 #elif defined GNULIB_POSIXCHECK
1046 # if HAVE_RAW_DECL_STRTOLL
1047 _GL_WARN_ON_USE (strtoll
, "strtoll is unportable - "
1048 "use gnulib module strtoll for portability");
1052 #if @GNULIB_STRTOULL@
1053 /* Parse an unsigned integer whose textual representation starts at STRING.
1054 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1055 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1057 If ENDPTR is not NULL, the address of the first byte after the integer is
1059 Upon overflow, the return value is ULLONG_MAX, and errno is set to
1061 # if !@HAVE_STRTOULL@
1062 _GL_FUNCDECL_SYS (strtoull
, unsigned long long,
1063 (const char *restrict string
, char **restrict endptr
,
1065 _GL_ARG_NONNULL ((1)));
1067 _GL_CXXALIAS_SYS (strtoull
, unsigned long long,
1068 (const char *restrict string
, char **restrict endptr
,
1070 _GL_CXXALIASWARN (strtoull
);
1071 #elif defined GNULIB_POSIXCHECK
1073 # if HAVE_RAW_DECL_STRTOULL
1074 _GL_WARN_ON_USE (strtoull
, "strtoull is unportable - "
1075 "use gnulib module strtoull for portability");
1079 #if @GNULIB_UNLOCKPT@
1080 /* Unlock the slave side of the pseudo-terminal whose master side is specified
1081 by FD, so that it can be opened. */
1082 # if !@HAVE_UNLOCKPT@
1083 _GL_FUNCDECL_SYS (unlockpt
, int, (int fd
));
1085 _GL_CXXALIAS_SYS (unlockpt
, int, (int fd
));
1086 _GL_CXXALIASWARN (unlockpt
);
1087 #elif defined GNULIB_POSIXCHECK
1089 # if HAVE_RAW_DECL_UNLOCKPT
1090 _GL_WARN_ON_USE (unlockpt
, "unlockpt is not portable - "
1091 "use gnulib module unlockpt for portability");
1095 #if @GNULIB_UNSETENV@
1096 /* Remove the variable NAME from the environment. */
1097 # if @REPLACE_UNSETENV@
1098 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1100 # define unsetenv rpl_unsetenv
1102 _GL_FUNCDECL_RPL (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1103 _GL_CXXALIAS_RPL (unsetenv
, int, (const char *name
));
1105 # if !@HAVE_DECL_UNSETENV@
1106 _GL_FUNCDECL_SYS (unsetenv
, int, (const char *name
) _GL_ARG_NONNULL ((1)));
1108 _GL_CXXALIAS_SYS (unsetenv
, int, (const char *name
));
1110 # if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
1111 _GL_CXXALIASWARN (unsetenv
);
1113 #elif defined GNULIB_POSIXCHECK
1115 # if HAVE_RAW_DECL_UNSETENV
1116 _GL_WARN_ON_USE (unsetenv
, "unsetenv is unportable - "
1117 "use gnulib module unsetenv for portability");
1121 /* Convert a wide character to a multibyte character. */
1123 # if @REPLACE_WCTOMB@
1124 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1126 # define wctomb rpl_wctomb
1128 _GL_FUNCDECL_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1129 _GL_CXXALIAS_RPL (wctomb
, int, (char *s
, wchar_t wc
));
1131 _GL_CXXALIAS_SYS (wctomb
, int, (char *s
, wchar_t wc
));
1134 _GL_CXXALIASWARN (wctomb
);
1139 #endif /* _@GUARD_PREFIX@_STDLIB_H */
1140 #endif /* _@GUARD_PREFIX@_STDLIB_H */