Check if the compiler knows about the __malloc__ attribute.
[oweals/tinc.git] / m4 / malloc.m4
1 #serial 1
2
3 dnl From Jim Meyering.
4 dnl Determine whether malloc accepts 0 as its argument.
5 dnl If it doesn't, arrange to use the replacement function.
6 dnl
7 dnl If you use this macro in a package, you should
8 dnl add the following two lines to acconfig.h:
9 dnl  /* Define to rpl_malloc if the replacement function should be used.  */
10 dnl  #undef malloc
11 dnl
12
13 AC_DEFUN(jm_FUNC_MALLOC,
14 [
15  if test x = y; then
16    dnl This code is deliberately never run via ./configure.
17    dnl FIXME: this is a gross hack to make autoheader put an entry
18    dnl for this symbol in config.h.in.
19    AC_CHECK_FUNCS(DONE_WORKING_MALLOC_CHECK)
20  fi
21  dnl xmalloc.c requires that this symbol be defined so it doesn't
22  dnl mistakenly use a broken malloc -- as it might if this test were omitted.
23  AC_DEFINE(HAVE_DONE_WORKING_MALLOC_CHECK, 1, [Needed for xmalloc.c])
24
25  AC_CACHE_CHECK([for working malloc], jm_cv_func_working_malloc,
26   [AC_TRY_RUN([
27     char *malloc ();
28     int
29     main ()
30     {
31       exit (malloc (0) ? 0 : 1);
32     }
33           ],
34          jm_cv_func_working_malloc=yes,
35          jm_cv_func_working_malloc=no,
36          dnl When crosscompiling, assume malloc is broken.
37          jm_cv_func_working_malloc=no)
38   ])
39   if test $jm_cv_func_working_malloc = no; then
40     dnl This was: LIBOBJS="$LIBOBJS malloc.$ac_objext"
41     AC_LIBOBJ([malloc])
42     AC_DEFINE(malloc, rpl_malloc, [Replacement malloc()])
43   fi
44 ])