realloc.m4 2.2 KB

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