2 dnl Copyright (C) 2007, 2009-2017 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 m4_version_prereq([2.70], [] ,[
9 # This is adapted with modifications from upstream Autoconf here:
10 # https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
11 AC_DEFUN([_AC_FUNC_REALLOC_IF],
13 AC_REQUIRE([AC_HEADER_STDC])dnl
14 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
15 AC_CHECK_HEADERS([stdlib.h])
16 AC_CACHE_CHECK([for GNU libc compatible realloc],
17 [ac_cv_func_realloc_0_nonnull],
20 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
26 [[char *p = realloc (0, 0);
31 [ac_cv_func_realloc_0_nonnull=yes],
32 [ac_cv_func_realloc_0_nonnull=no],
34 # Guess yes on platforms where we know the result.
35 *-gnu* | freebsd* | netbsd* | openbsd* \
36 | hpux* | solaris* | cygwin* | mingw*)
37 ac_cv_func_realloc_0_nonnull=yes ;;
38 # If we don't know, assume the worst.
39 *) ac_cv_func_realloc_0_nonnull=no ;;
43 AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
50 # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
51 # realloc if it is not.
52 AC_DEFUN([gl_FUNC_REALLOC_GNU],
54 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
55 dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
57 [AC_DEFINE([HAVE_REALLOC_GNU], [1],
58 [Define to 1 if your system has a GNU libc compatible 'realloc'
59 function, and to 0 otherwise.])],
60 [AC_DEFINE([HAVE_REALLOC_GNU], [0])
63 ])# gl_FUNC_REALLOC_GNU
65 # gl_FUNC_REALLOC_POSIX
66 # ---------------------
67 # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
68 # fails), and replace realloc if it is not.
69 AC_DEFUN([gl_FUNC_REALLOC_POSIX],
71 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
72 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
73 if test $gl_cv_func_malloc_posix = yes; then
74 AC_DEFINE([HAVE_REALLOC_POSIX], [1],
75 [Define if the 'realloc' function is POSIX compliant.])