summaryrefslogtreecommitdiffstats
path: root/gl/m4/free.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/free.m4')
-rw-r--r--gl/m4/free.m452
1 files changed, 52 insertions, 0 deletions
diff --git a/gl/m4/free.m4 b/gl/m4/free.m4
new file mode 100644
index 0000000..a7923b9
--- /dev/null
+++ b/gl/m4/free.m4
@@ -0,0 +1,52 @@
1# free.m4 serial 6
2# Copyright (C) 2003-2005, 2009-2021 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.
6
7# Written by Paul Eggert and Bruno Haible.
8
9AC_DEFUN([gl_FUNC_FREE],
10[
11 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
12
13 dnl In the next release of POSIX, free must preserve errno.
14 dnl https://www.austingroupbugs.net/view.php?id=385
15 dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
16 dnl So far, we know of three platforms that do this:
17 dnl * glibc >= 2.33, thanks to the fix for this bug:
18 dnl <https://sourceware.org/bugzilla/show_bug.cgi?id=17924>
19 dnl * OpenBSD >= 4.5, thanks to this commit:
20 dnl <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
21 dnl * Solaris, because its malloc() implementation is based on brk(),
22 dnl not mmap(); hence its free() implementation makes no system calls.
23 dnl For other platforms, you can only be sure if they state it in their
24 dnl documentation, or by code inspection of the free() implementation in libc.
25 AC_CACHE_CHECK([whether free is known to preserve errno],
26 [gl_cv_func_free_preserves_errno],
27 [AC_COMPILE_IFELSE(
28 [AC_LANG_PROGRAM(
29 [[#include <stdlib.h>
30 ]],
31 [[#if 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__)
32 #elif defined __OpenBSD__
33 #elif defined __sun
34 #else
35 #error "'free' is not known to preserve errno"
36 #endif
37 ]])],
38 [gl_cv_func_free_preserves_errno=yes],
39 [gl_cv_func_free_preserves_errno=no])
40 ])
41
42 case $gl_cv_func_free_preserves_errno in
43 *yes)
44 AC_DEFINE([HAVE_FREE_POSIX], [1],
45 [Define if the 'free' function is guaranteed to preserve errno.])
46 ;;
47 *) REPLACE_FREE=1 ;;
48 esac
49])
50
51# Prerequisites of lib/free.c.
52AC_DEFUN([gl_PREREQ_FREE], [:])