# calloc.m4
-# serial 34
+# serial 35
dnl Copyright (C) 2004-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
# If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
# and arrange to use a calloc wrapper function that does work in that case.
-# _AC_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT])
-# -------------------------------------
+# gl_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT])
+# ---------------------------------------
# If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT.
-AC_DEFUN([_AC_FUNC_CALLOC_IF],
+AC_DEFUN([gl_FUNC_CALLOC_IF],
[
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether calloc (0, n) and calloc (n, 0) return nonnull],
[ac_cv_func_calloc_0_nonnull],
- [if test $cross_compiling != yes; then
- ac_cv_func_calloc_0_nonnull=yes
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM(
- [AC_INCLUDES_DEFAULT],
- [[int result = 0;
- char * volatile p = calloc (0, 0);
- if (!p)
- result |= 1;
- free (p);
- return result;
- ]])],
- [],
- [ac_cv_func_calloc_0_nonnull=no])
- else
- case "$host_os" in
- # Guess yes on glibc systems.
- *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
- # Guess yes on musl systems.
- *-musl* | midipix*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
- # Guess yes on native Windows.
- mingw* | windows*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
- # If we don't know, obey --enable-cross-guesses.
- *) ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;;
- esac
- fi
- ])
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdlib.h>
+ /* Use pcalloc to test; "volatile" prevents the compiler
+ from optimizing the calloc call away. */
+ void *(*volatile pcalloc) (size_t, size_t) = calloc;]],
+ [[void *p = pcalloc (0, 0);
+ int result = !p;
+ free (p);
+ return result;]])],
+ [ac_cv_func_calloc_0_nonnull=yes],
+ [ac_cv_func_calloc_0_nonnull=no],
+ [AS_CASE([$host_os],
+ [# Guess yes on platforms where we know the result.
+ *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
+ | gnu* | *-musl* | midipix* | midnightbsd* \
+ | hpux* | solaris* | cygwin* | mingw* | windows* | msys*],
+ [ac_cv_func_malloc_0_nonnull="guessing yes"],
+ [# Guess as follows if we don't know.
+ ac_cv_func_malloc_0_nonnull=$gl_cross_guess_normal])])])
AS_CASE([$ac_cv_func_calloc_0_nonnull], [*yes], [$1], [$2])
])
REPLACE_CALLOC_FOR_CALLOC_GNU="$REPLACE_CALLOC_FOR_CALLOC_POSIX"
if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 0; then
- _AC_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1])
+ gl_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1])
fi
])# gl_FUNC_CALLOC_GNU