3 dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # This is adapted with modifications from upstream Autoconf here:
9 # https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455
10 AC_DEFUN([_AC_FUNC_REALLOC_IF],
12 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
13 AC_CACHE_CHECK([whether realloc (0, 0) returns nonnull],
14 [ac_cv_func_realloc_0_nonnull],
19 [[void *p = realloc (0, 0);
20 void * volatile vp = p;
25 [ac_cv_func_realloc_0_nonnull=yes],
26 [ac_cv_func_realloc_0_nonnull=no],
28 # Guess yes on platforms where we know the result.
29 *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
30 | gnu* | *-musl* | midipix* | midnightbsd* \
31 | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
32 ac_cv_func_realloc_0_nonnull="guessing yes" ;;
33 # If we don't know, obey --enable-cross-guesses.
34 *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
38 AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
43 # Replace realloc if it is not compatible with GNU libc.
44 AC_DEFUN([gl_FUNC_REALLOC_GNU],
46 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
47 AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
48 if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 0; then
49 _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC_FOR_REALLOC_GNU=1])
51 ])# gl_FUNC_REALLOC_GNU
53 # gl_FUNC_REALLOC_POSIX
54 # ---------------------
55 # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
56 # fails, and doesn't mess up with ptrdiff_t overflow),
57 # and replace realloc if it is not.
58 AC_DEFUN([gl_FUNC_REALLOC_POSIX],
60 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
61 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
62 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then
63 REPLACE_REALLOC_FOR_REALLOC_POSIX=1