Blame gettext-tools/gnulib-m4/malloc.m4

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