Debian Codegraph @

tools/gnulib/m4/realloc.m4

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