3 # Copyright (C) 2004 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Written by Jim Meyering.
21 # Determine whether calloc (N, S) returns non-NULL when N*S is zero,
22 # and returns NULL when N*S overflows.
23 # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
24 # and arrange to use a calloc wrapper function that does work in that case.
26 # _AC_FUNC_CALLOC_IF(IF-WORKS, IF-NOT)
27 # -------------------------------------
28 # If `calloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
29 AC_DEFUN([_AC_FUNC_CALLOC_IF],
30 [AC_REQUIRE([AC_HEADER_STDC])dnl
31 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
32 AC_CHECK_HEADERS(stdlib.h)
33 AC_CACHE_CHECK([for GNU libc compatible calloc], ac_cv_func_calloc_0_nonnull,
34 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
35 [exit (!calloc (0, 0) || calloc ((size_t) -1 / 8 + 1, 8));])],
36 [ac_cv_func_calloc_0_nonnull=yes],
37 [ac_cv_func_calloc_0_nonnull=no],
38 [ac_cv_func_calloc_0_nonnull=no])])
39 AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2])
45 # Report whether `calloc (0, 0)' is properly handled, and replace calloc if
47 AC_DEFUN([AC_FUNC_CALLOC],
49 [AC_DEFINE([HAVE_CALLOC], 1,
50 [Define to 1 if your system has a GNU libc compatible `calloc'
51 function, and to 0 otherwise.])],
52 [AC_DEFINE([HAVE_CALLOC], 0)
54 AC_DEFINE([calloc], [rpl_calloc],
55 [Define to rpl_calloc if the replacement function should be used.])])