3 # FIXME: remove this whole file once we can depend
4 # on having the definition from autoconf.
5 undefine([AC_FUNC_CALLOC])
7 # Determine whether calloc (N, S) returns non-NULL when N*S is zero.
8 # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
9 # and arrange to use a calloc wrapper function that does work in that case.
11 # _AC_FUNC_CALLOC_IF(IF-WORKS, IF-NOT)
12 # -------------------------------------
13 # If `calloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
14 AC_DEFUN([_AC_FUNC_CALLOC_IF],
15 [AC_REQUIRE([AC_HEADER_STDC])dnl
16 AC_CHECK_HEADERS(stdlib.h)
17 AC_CACHE_CHECK([for GNU libc compatible calloc], ac_cv_func_calloc_0_nonnull,
20 [[#if STDC_HEADERS || HAVE_STDLIB_H
26 [exit (calloc (0, 0) ? 0 : 1);])],
27 [ac_cv_func_calloc_0_nonnull=yes],
28 [ac_cv_func_calloc_0_nonnull=no],
29 [ac_cv_func_calloc_0_nonnull=no])])
30 AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2])
36 # Report whether `calloc (0, 0)' is properly handled, and replace calloc if
38 AC_DEFUN([AC_FUNC_CALLOC],
40 [AC_DEFINE([HAVE_CALLOC], 1,
41 [Define to 1 if your system has a GNU libc compatible `calloc'
42 function, and to 0 otherwise.])],
43 [AC_DEFINE([HAVE_CALLOC], 0)
45 AC_DEFINE([calloc], [rpl_calloc],
46 [Define to rpl_calloc if the replacement function should be used.])])