Blame m4/realloc.m4

Packit 709fb3
# realloc.m4 serial 14
Packit 709fb3
dnl Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
dnl This file is free software; the Free Software Foundation
Packit 709fb3
dnl gives unlimited permission to copy and/or distribute it,
Packit 709fb3
dnl with or without modifications, as long as this notice is preserved.
Packit 709fb3
Packit 709fb3
m4_version_prereq([2.70], [] ,[
Packit 709fb3
Packit 709fb3
# This is adapted with modifications from upstream Autoconf here:
Packit 709fb3
# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
Packit 709fb3
AC_DEFUN([_AC_FUNC_REALLOC_IF],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_HEADER_STDC])dnl
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
Packit 709fb3
  AC_CHECK_HEADERS([stdlib.h])
Packit 709fb3
  AC_CACHE_CHECK([for GNU libc compatible realloc],
Packit 709fb3
    [ac_cv_func_realloc_0_nonnull],
Packit 709fb3
    [AC_RUN_IFELSE(
Packit 709fb3
       [AC_LANG_PROGRAM(
Packit 709fb3
          [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
Packit 709fb3
            # include <stdlib.h>
Packit 709fb3
            #else
Packit 709fb3
            char *realloc ();
Packit 709fb3
            #endif
Packit 709fb3
          ]],
Packit 709fb3
          [[char *p = realloc (0, 0);
Packit 709fb3
            int result = !p;
Packit 709fb3
            free (p);
Packit 709fb3
            return result;]])
Packit 709fb3
       ],
Packit 709fb3
       [ac_cv_func_realloc_0_nonnull=yes],
Packit 709fb3
       [ac_cv_func_realloc_0_nonnull=no],
Packit 709fb3
       [case "$host_os" in
Packit 709fb3
          # Guess yes on platforms where we know the result.
Packit 709fb3
          *-gnu* | freebsd* | netbsd* | openbsd* \
Packit 709fb3
          | hpux* | solaris* | cygwin* | mingw*)
Packit 709fb3
            ac_cv_func_realloc_0_nonnull=yes ;;
Packit 709fb3
          # If we don't know, assume the worst.
Packit 709fb3
          *) ac_cv_func_realloc_0_nonnull=no ;;
Packit 709fb3
        esac
Packit 709fb3
       ])
Packit 709fb3
    ])
Packit 709fb3
  AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
Packit 709fb3
])# AC_FUNC_REALLOC
Packit 709fb3
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
# gl_FUNC_REALLOC_GNU
Packit 709fb3
# -------------------
Packit 709fb3
# Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
Packit 709fb3
# realloc if it is not.
Packit 709fb3
AC_DEFUN([gl_FUNC_REALLOC_GNU],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit 709fb3
  dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
Packit 709fb3
  _AC_FUNC_REALLOC_IF(
Packit 709fb3
    [AC_DEFINE([HAVE_REALLOC_GNU], [1],
Packit 709fb3
               [Define to 1 if your system has a GNU libc compatible 'realloc'
Packit 709fb3
                function, and to 0 otherwise.])],
Packit 709fb3
    [AC_DEFINE([HAVE_REALLOC_GNU], [0])
Packit 709fb3
     REPLACE_REALLOC=1
Packit 709fb3
    ])
Packit 709fb3
])# gl_FUNC_REALLOC_GNU
Packit 709fb3
Packit 709fb3
# gl_FUNC_REALLOC_POSIX
Packit 709fb3
# ---------------------
Packit 709fb3
# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
Packit 709fb3
# fails), and replace realloc if it is not.
Packit 709fb3
AC_DEFUN([gl_FUNC_REALLOC_POSIX],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit 709fb3
  AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
Packit 709fb3
  if test $gl_cv_func_malloc_posix = yes; then
Packit 709fb3
    AC_DEFINE([HAVE_REALLOC_POSIX], [1],
Packit 709fb3
      [Define if the 'realloc' function is POSIX compliant.])
Packit 709fb3
  else
Packit 709fb3
    REPLACE_REALLOC=1
Packit 709fb3
  fi
Packit 709fb3
])