Debian Codegraph @

m4/free.m4

raw
1 # free.m4
2 # serial 6
3 dnl Copyright (C) 2003-2005, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 # Written by Paul Eggert and Bruno Haible.
10
11 AC_DEFUN([gl_FUNC_FREE],
12 [
13 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
14
15 dnl In the next release of POSIX, free must preserve errno.
16 dnl https://www.austingroupbugs.net/view.php?id=385
17 dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
18 dnl So far, we know of three platforms that do this:
19 dnl * glibc >= 2.33, thanks to the fix for this bug:
20 dnl <https://sourceware.org/bugzilla/show_bug.cgi?id=17924>
21 dnl * OpenBSD >= 4.5, thanks to this commit:
22 dnl <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
23 dnl * Solaris, because its malloc() implementation is based on brk(),
24 dnl not mmap(); hence its free() implementation makes no system calls.
25 dnl For other platforms, you can only be sure if they state it in their
26 dnl documentation, or by code inspection of the free() implementation in libc.
27 AC_CACHE_CHECK([whether free is known to preserve errno],
28 [gl_cv_func_free_preserves_errno],
29 [AC_COMPILE_IFELSE(
30 [AC_LANG_PROGRAM(
31 [[#include <stdlib.h>
32 ]],
33 [[#if 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__)
34 #elif defined __OpenBSD__
35 #elif defined __sun
36 #else
37 #error "'free' is not known to preserve errno"
38 #endif
39 ]])],
40 [gl_cv_func_free_preserves_errno=yes],
41 [gl_cv_func_free_preserves_errno=no])
42 ])
43
44 case $gl_cv_func_free_preserves_errno in
45 *yes)
46 AC_DEFINE([HAVE_FREE_POSIX], [1],
47 [Define if the 'free' function is guaranteed to preserve errno.])
48 ;;
49 *) REPLACE_FREE=1 ;;
50 esac
51 ])
52
53 # Prerequisites of lib/free.c.
54 AC_DEFUN([gl_PREREQ_FREE], [:])