realloc.m4 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # realloc.m4 serial 19
  2. dnl Copyright (C) 2007, 2009-2021 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/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
  8. AC_DEFUN([_AC_FUNC_REALLOC_IF],
  9. [
  10. AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
  11. AC_CACHE_CHECK([for GNU libc compatible realloc],
  12. [ac_cv_func_realloc_0_nonnull],
  13. [AC_RUN_IFELSE(
  14. [AC_LANG_PROGRAM(
  15. [[#include <stdlib.h>
  16. ]],
  17. [[char *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* | gnu* | *-musl* | freebsd* | netbsd* | openbsd* \
  27. | hpux* | solaris* | cygwin* | mingw*)
  28. ac_cv_func_realloc_0_nonnull="guessing yes" ;;
  29. # If we don't know, obey --enable-cross-guesses.
  30. *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
  31. esac
  32. ])
  33. ])
  34. case "$ac_cv_func_realloc_0_nonnull" in
  35. *yes)
  36. $1
  37. ;;
  38. *)
  39. $2
  40. ;;
  41. esac
  42. ])# AC_FUNC_REALLOC
  43. # gl_FUNC_REALLOC_GNU
  44. # -------------------
  45. # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
  46. # realloc if it is not.
  47. AC_DEFUN([gl_FUNC_REALLOC_GNU],
  48. [
  49. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  50. dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
  51. _AC_FUNC_REALLOC_IF(
  52. [AC_DEFINE([HAVE_REALLOC_GNU], [1],
  53. [Define to 1 if your system has a GNU libc compatible 'realloc'
  54. function, and to 0 otherwise.])],
  55. [AC_DEFINE([HAVE_REALLOC_GNU], [0])
  56. REPLACE_REALLOC=1
  57. ])
  58. ])# gl_FUNC_REALLOC_GNU
  59. # gl_FUNC_REALLOC_POSIX
  60. # ---------------------
  61. # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
  62. # fails), and replace realloc if it is not.
  63. AC_DEFUN([gl_FUNC_REALLOC_POSIX],
  64. [
  65. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  66. AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
  67. if test $gl_cv_func_malloc_posix = yes; then
  68. AC_DEFINE([HAVE_REALLOC_POSIX], [1],
  69. [Define if the 'realloc' function is POSIX compliant.])
  70. else
  71. REPLACE_REALLOC=1
  72. fi
  73. ])