source: trunk/coreutils/m4/calloc.m4@ 2747

Last change on this file since 2747 was 2554, checked in by bird, 20 years ago

coretuils-5.94

File size: 1.7 KB
Line 
1# calloc.m4 serial 5
2
3# Copyright (C) 2004, 2005 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.
7
8# Written by Jim Meyering.
9
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.
14
15# _AC_FUNC_CALLOC_IF(IF-WORKS, IF-NOT)
16# -------------------------------------
17# If `calloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
18AC_DEFUN([_AC_FUNC_CALLOC_IF],
19[AC_REQUIRE([AC_HEADER_STDC])dnl
20AC_REQUIRE([AC_TYPE_SIZE_T])dnl
21AC_CACHE_CHECK([for GNU libc compatible calloc], ac_cv_func_calloc_0_nonnull,
22[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
23 [exit (!calloc (0, 0) || calloc ((size_t) -1 / 8 + 1, 8));])],
24 [ac_cv_func_calloc_0_nonnull=yes],
25 [ac_cv_func_calloc_0_nonnull=no],
26 [ac_cv_func_calloc_0_nonnull=no])])
27AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2])
28])# AC_FUNC_CALLOC
29
30
31# AC_FUNC_CALLOC
32# ---------------
33# Report whether `calloc (0, 0)' is properly handled, and replace calloc if
34# needed.
35AC_DEFUN([AC_FUNC_CALLOC],
36[_AC_FUNC_CALLOC_IF(
37 [AC_DEFINE([HAVE_CALLOC], 1,
38 [Define to 1 if your system has a GNU libc compatible `calloc'
39 function, and to 0 otherwise.])],
40 [AC_DEFINE([HAVE_CALLOC], 0)
41 AC_LIBOBJ([calloc])
42 AC_DEFINE([calloc], [rpl_calloc],
43 [Define to rpl_calloc if the replacement function should be used.])])
44])# AC_FUNC_CALLOC
Note: See TracBrowser for help on using the repository browser.