3 # Copyright (C) 2004-2017 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
8 # Written by Jim Meyering.
10 # Determine whether calloc (N, S) returns non-NULL when N*S is zero,
11 # and returns NULL when N*S overflows.
12 # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
13 # and arrange to use a calloc wrapper function that does work in that case.
15 # _AC_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT])
16 # -------------------------------------
17 # If 'calloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
18 AC_DEFUN([_AC_FUNC_CALLOC_IF],
20 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
21 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
22 AC_CACHE_CHECK([for GNU libc compatible calloc],
23 [ac_cv_func_calloc_0_nonnull],
26 [AC_INCLUDES_DEFAULT],
28 char *p = calloc (0, 0);
32 p = calloc ((size_t) -1 / 8 + 1, 8);
38 [ac_cv_func_calloc_0_nonnull=yes],
39 [ac_cv_func_calloc_0_nonnull=no],
41 # Guess yes on glibc systems.
42 *-gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
43 # If we don't know, assume the worst.
44 *) ac_cv_func_calloc_0_nonnull="guessing no" ;;
47 case "$ac_cv_func_calloc_0_nonnull" in
60 # Report whether 'calloc (0, 0)' is properly handled, and replace calloc if
62 AC_DEFUN([gl_FUNC_CALLOC_GNU],
64 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
66 [AC_DEFINE([HAVE_CALLOC_GNU], [1],
67 [Define to 1 if your system has a GNU libc compatible 'calloc'
68 function, and to 0 otherwise.])],
69 [AC_DEFINE([HAVE_CALLOC_GNU], [0])
72 ])# gl_FUNC_CALLOC_GNU
75 # gl_FUNC_CALLOC_POSIX
76 # --------------------
77 # Test whether 'calloc' is POSIX compliant (sets errno to ENOMEM when it
78 # fails), and replace calloc if it is not.
79 AC_DEFUN([gl_FUNC_CALLOC_POSIX],
81 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
82 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
83 if test $gl_cv_func_malloc_posix = yes; then
84 AC_DEFINE([HAVE_CALLOC_POSIX], [1],
85 [Define if the 'calloc' function is POSIX compliant.])