Debian Codegraph @

m4/realloc.m4

raw
1 # realloc.m4 serial 29
2 dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # This is adapted with modifications from upstream Autoconf here:
8 # https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455
9 AC_DEFUN([_AC_FUNC_REALLOC_IF],
10 [
11 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
12 AC_CACHE_CHECK([whether realloc (0, 0) returns nonnull],
13 [ac_cv_func_realloc_0_nonnull],
14 [AC_RUN_IFELSE(
15 [AC_LANG_PROGRAM(
16 [[#include <stdlib.h>
17 ]],
18 [[void *p = realloc (0, 0);
19 void * volatile vp = p;
20 int result = !vp;
21 free (p);
22 return result;]])
23 ],
24 [ac_cv_func_realloc_0_nonnull=yes],
25 [ac_cv_func_realloc_0_nonnull=no],
26 [case "$host_os" in
27 # Guess yes on platforms where we know the result.
28 *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
29 | gnu* | *-musl* | midipix* | midnightbsd* \
30 | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
31 ac_cv_func_realloc_0_nonnull="guessing yes" ;;
32 # If we don't know, obey --enable-cross-guesses.
33 *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
34 esac
35 ])
36 ])
37 AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
38 ])# AC_FUNC_REALLOC
39
40 # gl_FUNC_REALLOC_GNU
41 # -------------------
42 # Replace realloc if it is not compatible with GNU libc.
43 AC_DEFUN([gl_FUNC_REALLOC_GNU],
44 [
45 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
46 AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
47 if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 0; then
48 _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC_FOR_REALLOC_GNU=1])
49 fi
50 ])# gl_FUNC_REALLOC_GNU
51
52 # gl_FUNC_REALLOC_POSIX
53 # ---------------------
54 # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
55 # fails, and doesn't mess up with ptrdiff_t overflow),
56 # and replace realloc if it is not.
57 AC_DEFUN([gl_FUNC_REALLOC_POSIX],
58 [
59 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
60 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
61 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then
62 REPLACE_REALLOC_FOR_REALLOC_POSIX=1
63 fi
64 ])