2 dnl Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 # This is adapted with modifications from upstream Autoconf here:
8 # https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
9 AC_DEFUN([_AC_FUNC_REALLOC_IF],
11 AC_REQUIRE([AC_HEADER_STDC])dnl
12 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
13 AC_CHECK_HEADERS([stdlib.h])
14 AC_CACHE_CHECK([for GNU libc compatible realloc],
15 [ac_cv_func_realloc_0_nonnull],
18 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
24 [[char *p = realloc (0, 0);
29 [ac_cv_func_realloc_0_nonnull=yes],
30 [ac_cv_func_realloc_0_nonnull=no],
32 # Guess yes on platforms where we know the result.
33 *-gnu* | gnu* | *-musl* | freebsd* | netbsd* | openbsd* \
34 | hpux* | solaris* | cygwin* | mingw*)
35 ac_cv_func_realloc_0_nonnull="guessing yes" ;;
36 # If we don't know, obey --enable-cross-guesses.
37 *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
41 case "$ac_cv_func_realloc_0_nonnull" in
53 # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
54 # realloc if it is not.
55 AC_DEFUN([gl_FUNC_REALLOC_GNU],
57 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
58 dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
60 [AC_DEFINE([HAVE_REALLOC_GNU], [1],
61 [Define to 1 if your system has a GNU libc compatible 'realloc'
62 function, and to 0 otherwise.])],
63 [AC_DEFINE([HAVE_REALLOC_GNU], [0])
66 ])# gl_FUNC_REALLOC_GNU
68 # gl_FUNC_REALLOC_POSIX
69 # ---------------------
70 # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
71 # fails), and replace realloc if it is not.
72 AC_DEFUN([gl_FUNC_REALLOC_POSIX],
74 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
75 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
76 if test $gl_cv_func_malloc_posix = yes; then
77 AC_DEFINE([HAVE_REALLOC_POSIX], [1],
78 [Define if the 'realloc' function is POSIX compliant.])