Blame gnulib/m4/malloc.m4

Packit Service 51e54d
# malloc.m4 serial 14
Packit Service 51e54d
dnl Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc.
Packit Service 51e54d
dnl This file is free software; the Free Software Foundation
Packit Service 51e54d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 51e54d
dnl with or without modifications, as long as this notice is preserved.
Packit Service 51e54d
Packit Service 51e54d
m4_version_prereq([2.70], [] ,[
Packit Service 51e54d
Packit Service 51e54d
# This is taken from the following Autoconf patch:
Packit Service 51e54d
# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
Packit Service 51e54d
AC_DEFUN([_AC_FUNC_MALLOC_IF],
Packit Service 51e54d
[
Packit Service 51e54d
  AC_REQUIRE([AC_HEADER_STDC])dnl
Packit Service 51e54d
  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
Packit Service 51e54d
  AC_CHECK_HEADERS([stdlib.h])
Packit Service 51e54d
  AC_CACHE_CHECK([for GNU libc compatible malloc],
Packit Service 51e54d
    [ac_cv_func_malloc_0_nonnull],
Packit Service 51e54d
    [AC_RUN_IFELSE(
Packit Service 51e54d
       [AC_LANG_PROGRAM(
Packit Service 51e54d
          [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
Packit Service 51e54d
            # include <stdlib.h>
Packit Service 51e54d
            #else
Packit Service 51e54d
            char *malloc ();
Packit Service 51e54d
            #endif
Packit Service 51e54d
          ]],
Packit Service 51e54d
          [[return ! malloc (0);]])
Packit Service 51e54d
       ],
Packit Service 51e54d
       [ac_cv_func_malloc_0_nonnull=yes],
Packit Service 51e54d
       [ac_cv_func_malloc_0_nonnull=no],
Packit Service 51e54d
       [case "$host_os" in
Packit Service 51e54d
          # Guess yes on platforms where we know the result.
Packit Service 51e54d
          *-gnu* | freebsd* | netbsd* | openbsd* \
Packit Service 51e54d
          | hpux* | solaris* | cygwin* | mingw*)
Packit Service 51e54d
            ac_cv_func_malloc_0_nonnull=yes ;;
Packit Service 51e54d
          # If we don't know, assume the worst.
Packit Service 51e54d
          *) ac_cv_func_malloc_0_nonnull=no ;;
Packit Service 51e54d
        esac
Packit Service 51e54d
       ])
Packit Service 51e54d
    ])
Packit Service 51e54d
  AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
Packit Service 51e54d
])# _AC_FUNC_MALLOC_IF
Packit Service 51e54d
Packit Service 51e54d
])
Packit Service 51e54d
Packit Service 51e54d
# gl_FUNC_MALLOC_GNU
Packit Service 51e54d
# ------------------
Packit Service 51e54d
# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
Packit Service 51e54d
# it is not.
Packit Service 51e54d
AC_DEFUN([gl_FUNC_MALLOC_GNU],
Packit Service 51e54d
[
Packit Service 51e54d
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit Service 51e54d
  dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
Packit Service 51e54d
  _AC_FUNC_MALLOC_IF(
Packit Service 51e54d
    [AC_DEFINE([HAVE_MALLOC_GNU], [1],
Packit Service 51e54d
               [Define to 1 if your system has a GNU libc compatible 'malloc'
Packit Service 51e54d
                function, and to 0 otherwise.])],
Packit Service 51e54d
    [AC_DEFINE([HAVE_MALLOC_GNU], [0])
Packit Service 51e54d
     REPLACE_MALLOC=1
Packit Service 51e54d
    ])
Packit Service 51e54d
])
Packit Service 51e54d
Packit Service 51e54d
# gl_FUNC_MALLOC_POSIX
Packit Service 51e54d
# --------------------
Packit Service 51e54d
# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
Packit Service 51e54d
# fails), and replace malloc if it is not.
Packit Service 51e54d
AC_DEFUN([gl_FUNC_MALLOC_POSIX],
Packit Service 51e54d
[
Packit Service 51e54d
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit Service 51e54d
  AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
Packit Service 51e54d
  if test $gl_cv_func_malloc_posix = yes; then
Packit Service 51e54d
    AC_DEFINE([HAVE_MALLOC_POSIX], [1],
Packit Service 51e54d
      [Define if the 'malloc' function is POSIX compliant.])
Packit Service 51e54d
  else
Packit Service 51e54d
    REPLACE_MALLOC=1
Packit Service 51e54d
  fi
Packit Service 51e54d
])
Packit Service 51e54d
Packit Service 51e54d
# Test whether malloc, realloc, calloc are POSIX compliant,
Packit Service 51e54d
# Set gl_cv_func_malloc_posix to yes or no accordingly.
Packit Service 51e54d
AC_DEFUN([gl_CHECK_MALLOC_POSIX],
Packit Service 51e54d
[
Packit Service 51e54d
  AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
Packit Service 51e54d
    [gl_cv_func_malloc_posix],
Packit Service 51e54d
    [
Packit Service 51e54d
      dnl It is too dangerous to try to allocate a large amount of memory:
Packit Service 51e54d
      dnl some systems go to their knees when you do that. So assume that
Packit Service 51e54d
      dnl all Unix implementations of the function are POSIX compliant.
Packit Service 51e54d
      AC_COMPILE_IFELSE(
Packit Service 51e54d
        [AC_LANG_PROGRAM(
Packit Service 51e54d
           [[]],
Packit Service 51e54d
           [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
Packit Service 51e54d
             choke me
Packit Service 51e54d
             #endif
Packit Service 51e54d
            ]])],
Packit Service 51e54d
        [gl_cv_func_malloc_posix=yes],
Packit Service 51e54d
        [gl_cv_func_malloc_posix=no])
Packit Service 51e54d
    ])
Packit Service 51e54d
])