3 # Determine whether calloc (N, S) returns non-NULL when N*S is zero.
4 # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
5 # and arrange to use a calloc wrapper function that does work in that case.
7 # _AC_FUNC_CALLOC_IF(IF-WORKS, IF-NOT)
8 # -------------------------------------
9 # If `calloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
10 AC_DEFUN([_AC_FUNC_CALLOC_IF],
11 [AC_REQUIRE([AC_HEADER_STDC])dnl
12 AC_CHECK_HEADERS(stdlib.h)
13 AC_CACHE_CHECK([for GNU libc compatible calloc], ac_cv_func_calloc_0_nonnull,
16 [[#if STDC_HEADERS || HAVE_STDLIB_H
22 [exit (calloc (0, 0) ? 0 : 1);])],
23 [ac_cv_func_calloc_0_nonnull=yes],
24 [ac_cv_func_calloc_0_nonnull=no],
25 [ac_cv_func_calloc_0_nonnull=no])])
26 AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2])
32 # Report whether `calloc (0, 0)' is properly handled, and replace calloc if
34 AC_DEFUN([AC_FUNC_CALLOC],
36 [AC_DEFINE([HAVE_CALLOC], 1,
37 [Define to 1 if your system has a GNU libc compatible `calloc'
38 function, and to 0 otherwise.])],
39 [AC_DEFINE([HAVE_CALLOC], 0)
41 AC_DEFINE([calloc], [rpl_calloc],
42 [Define to rpl_calloc if the replacement function should be used.])])