Add 'free' module.
[gnulib.git] / m4 / free.m4
1 # Check whether free (NULL) is supposed to work.
2
3 # Copyright (C) 2003 Free Software Foundation, Inc.
4
5 # This file is free software, distributed under the terms of the GNU
6 # General Public License.  As a special exception to the GNU General
7 # Public License, this file may be distributed as part of a program
8 # that contains a configuration script generated by Autoconf, under
9 # the same distribution terms as the rest of that program.
10
11 # Written by Paul Eggert.
12
13 # We can't test for free (NULL) even at runtime, since it might
14 # happen to "work" for our test program, but not in general.  So, be
15 # conservative and use feature tests for relatively modern hosts,
16 # where free (NULL) is known to work.  This costs a bit of
17 # performance on some older hosts, but we can fix that later if
18 # needed.
19
20 AC_DEFUN([gl_FUNC_FREE],
21 [
22   AC_CHECK_HEADERS_ONCE(unistd.h)
23   AC_CACHE_CHECK([whether free (NULL) is known to work],
24     [gl_cv_func_free],
25     [AC_COMPILE_IFELSE(
26        [AC_LANG_PROGRAM(
27           [[@%:@if HAVE_UNISTD_H
28               @%:@include <unistd.h>
29             @%:@endif]],
30           [[@%:@if _POSIX_VERSION < 199009L && \
31                 (defined unix || defined _unix || defined _unix_ \
32                  || defined __unix || defined __unix__)
33               @%:@error "'free (NULL)' is not known to work"
34             @%:@endif]])],
35        [gl_cv_func_free=yes],
36        [gl_cv_func_free=no])])
37
38   if test $gl_cv_func_free = yes; then
39     AC_LIBOBJ(free)
40     AC_DEFINE(free, rpl_free,
41       [Define to rpl_free if the replacement function should be used.])
42   fi
43 ])
44
45 # Prerequisites of lib/free.c.
46 AC_DEFUN([gl_PREREQ_FREE], [:])