free-posix: Assume future POSIX compliance only on OpenBSD and Solaris.
[gnulib.git] / m4 / free.m4
blob53df7439b53224186a57b7b3cd06a0ac6b9a6fd3
1 # free.m4 serial 4
2 # Copyright (C) 2003-2005, 2009-2020 Free Software Foundation, Inc.
3 # This file is free software; the Free Software Foundation
4 # gives unlimited permission to copy and/or distribute it,
5 # with or without modifications, as long as this notice is preserved.
7 # Written by Paul Eggert and Bruno Haible.
9 AC_DEFUN([gl_FUNC_FREE],
11   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
12   AC_REQUIRE([AC_CANONICAL_HOST])
14   dnl In the next release of POSIX, free must preserve errno.
15   dnl https://www.austingroupbugs.net/view.php?id=385
16   dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
17   dnl So far, we know of two platforms that do this:
18   dnl * OpenBSD >= 4.5, thanks to this commit:
19   dnl   <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
20   dnl * Solaris, because its malloc() implementation is based on brk(),
21   dnl   not mmap(); hence its free() implementation makes no system calls.
22   dnl For other platforms, you can only be sure if they state it in their
23   dnl documentation, or by code inspection of the free() implementation in libc.
24   AC_CACHE_CHECK([whether free is known to preserve errno],
25     [gl_cv_func_free_preserves_errno],
26     [case "$host_os" in
27        # Say yes only if we know it.
28        openbsd* | solaris*)
29          gl_cv_func_free_preserves_errno=yes
30          ;;
31        # It's no on Linux, for implementations that call munmap(), due to
32        # /proc/sys/vm/max_map_count.
33        linux*)
34          gl_cv_func_free_preserves_errno=no
35          ;;
36        # If we don't know, obey --enable-cross-guesses.
37        *)
38          gl_cv_func_free_preserves_errno="$gl_cross_guess_normal"
39          ;;
40      esac
41     ])
43   case $gl_cv_func_free_preserves_errno in
44    *yes) ;;
45    *) REPLACE_FREE=1 ;;
46   esac
49 # Prerequisites of lib/free.c.
50 AC_DEFUN([gl_PREREQ_FREE], [:])