realloc.m4 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # realloc.m4 serial 13
  2. dnl Copyright (C) 2007, 2009-2013 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. m4_version_prereq([2.70], [] ,[
  7. # This is taken from the following Autoconf patch:
  8. # http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
  9. AC_DEFUN([_AC_FUNC_REALLOC_IF],
  10. [
  11. AC_REQUIRE([AC_HEADER_STDC])dnl
  12. AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
  13. AC_CHECK_HEADERS([stdlib.h])
  14. AC_CACHE_CHECK([for GNU libc compatible realloc],
  15. [ac_cv_func_realloc_0_nonnull],
  16. [AC_RUN_IFELSE(
  17. [AC_LANG_PROGRAM(
  18. [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
  19. # include <stdlib.h>
  20. #else
  21. char *realloc ();
  22. #endif
  23. ]],
  24. [[return ! realloc (0, 0);]])
  25. ],
  26. [ac_cv_func_realloc_0_nonnull=yes],
  27. [ac_cv_func_realloc_0_nonnull=no],
  28. [case "$host_os" in
  29. # Guess yes on platforms where we know the result.
  30. *-gnu* | freebsd* | netbsd* | openbsd* \
  31. | hpux* | solaris* | cygwin* | mingw*)
  32. ac_cv_func_realloc_0_nonnull=yes ;;
  33. # If we don't know, assume the worst.
  34. *) ac_cv_func_realloc_0_nonnull=no ;;
  35. esac
  36. ])
  37. ])
  38. AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
  39. ])# AC_FUNC_REALLOC
  40. ])
  41. # gl_FUNC_REALLOC_GNU
  42. # -------------------
  43. # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
  44. # realloc if it is not.
  45. AC_DEFUN([gl_FUNC_REALLOC_GNU],
  46. [
  47. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  48. dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
  49. _AC_FUNC_REALLOC_IF(
  50. [AC_DEFINE([HAVE_REALLOC_GNU], [1],
  51. [Define to 1 if your system has a GNU libc compatible 'realloc'
  52. function, and to 0 otherwise.])],
  53. [AC_DEFINE([HAVE_REALLOC_GNU], [0])
  54. REPLACE_REALLOC=1
  55. ])
  56. ])# gl_FUNC_REALLOC_GNU
  57. # gl_FUNC_REALLOC_POSIX
  58. # ---------------------
  59. # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
  60. # fails), and replace realloc if it is not.
  61. AC_DEFUN([gl_FUNC_REALLOC_POSIX],
  62. [
  63. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  64. AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
  65. if test $gl_cv_func_malloc_posix = yes; then
  66. AC_DEFINE([HAVE_REALLOC_POSIX], [1],
  67. [Define if the 'realloc' function is POSIX compliant.])
  68. else
  69. REPLACE_REALLOC=1
  70. fi
  71. ])