fee15ddbccfdbc5c8b136abb0b37c0e60a75e2a4
[gnulib.git] / m4 / calloc.m4
1 #serial 1
2
3 # FIXME: remove this whole file once we can depend
4 # on having the definition from autoconf.
5 undefine([AC_FUNC_CALLOC])
6
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.
10
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,
18 [AC_RUN_IFELSE(
19 [AC_LANG_PROGRAM(
20 [[#if STDC_HEADERS || HAVE_STDLIB_H
21 # include <stdlib.h>
22 #else
23 char *calloc ();
24 #endif
25 ]],
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])
31 ])# AC_FUNC_CALLOC
32
33
34 # AC_FUNC_CALLOC
35 # ---------------
36 # Report whether `calloc (0, 0)' is properly handled, and replace calloc if
37 # needed.
38 AC_DEFUN([AC_FUNC_CALLOC],
39 [_AC_FUNC_CALLOC_IF(
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)
44    AC_LIBOBJ([calloc])
45    AC_DEFINE([calloc], [rpl_calloc],
46       [Define to rpl_calloc if the replacement function should be used.])])
47 ])# AC_FUNC_CALLOC