xref: /netbsd-src/external/gpl2/diffutils/dist/m4/malloc.m4 (revision 75f6d617e282811cb173c2ccfbf5df0dd71f7045)
1*75f6d617Schristos#serial 5
2*75f6d617Schristos
3*75f6d617Schristosdnl From Jim Meyering.
4*75f6d617Schristosdnl Determine whether malloc accepts 0 as its argument.
5*75f6d617Schristosdnl If it doesn't, arrange to use the replacement function.
6*75f6d617Schristosdnl
7*75f6d617Schristos
8*75f6d617SchristosAC_DEFUN([jm_FUNC_MALLOC],
9*75f6d617Schristos[
10*75f6d617Schristos dnl xmalloc.c requires that this symbol be defined so it doesn't
11*75f6d617Schristos dnl mistakenly use a broken malloc -- as it might if this test were omitted.
12*75f6d617Schristos AC_DEFINE(HAVE_DONE_WORKING_MALLOC_CHECK, 1,
13*75f6d617Schristos           [Define if the malloc check has been performed. ])
14*75f6d617Schristos
15*75f6d617Schristos AC_CACHE_CHECK([for working malloc], jm_cv_func_working_malloc,
16*75f6d617Schristos  [AC_TRY_RUN([
17*75f6d617Schristos    char *malloc ();
18*75f6d617Schristos    int
19*75f6d617Schristos    main ()
20*75f6d617Schristos    {
21*75f6d617Schristos      exit (malloc (0) ? 0 : 1);
22*75f6d617Schristos    }
23*75f6d617Schristos	  ],
24*75f6d617Schristos	 jm_cv_func_working_malloc=yes,
25*75f6d617Schristos	 jm_cv_func_working_malloc=no,
26*75f6d617Schristos	 dnl When crosscompiling, assume malloc is broken.
27*75f6d617Schristos	 jm_cv_func_working_malloc=no)
28*75f6d617Schristos  ])
29*75f6d617Schristos  if test $jm_cv_func_working_malloc = no; then
30*75f6d617Schristos    AC_LIBOBJ(malloc)
31*75f6d617Schristos    AC_DEFINE(malloc, rpl_malloc,
32*75f6d617Schristos      [Define to rpl_malloc if the replacement function should be used.])
33*75f6d617Schristos  fi
34*75f6d617Schristos])
35