malloc.m4 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # malloc.m4 serial 13
  2. dnl Copyright (C) 2007, 2009-2012 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. # gl_FUNC_MALLOC_GNU
  7. # ------------------
  8. # Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
  9. # it is not.
  10. AC_DEFUN([gl_FUNC_MALLOC_GNU],
  11. [
  12. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  13. dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
  14. _AC_FUNC_MALLOC_IF(
  15. [AC_DEFINE([HAVE_MALLOC_GNU], [1],
  16. [Define to 1 if your system has a GNU libc compatible 'malloc'
  17. function, and to 0 otherwise.])],
  18. [AC_DEFINE([HAVE_MALLOC_GNU], [0])
  19. REPLACE_MALLOC=1
  20. ])
  21. ])
  22. # gl_FUNC_MALLOC_POSIX
  23. # --------------------
  24. # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
  25. # fails), and replace malloc if it is not.
  26. AC_DEFUN([gl_FUNC_MALLOC_POSIX],
  27. [
  28. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  29. AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
  30. if test $gl_cv_func_malloc_posix = yes; then
  31. AC_DEFINE([HAVE_MALLOC_POSIX], [1],
  32. [Define if the 'malloc' function is POSIX compliant.])
  33. else
  34. REPLACE_MALLOC=1
  35. fi
  36. ])
  37. # Test whether malloc, realloc, calloc are POSIX compliant,
  38. # Set gl_cv_func_malloc_posix to yes or no accordingly.
  39. AC_DEFUN([gl_CHECK_MALLOC_POSIX],
  40. [
  41. AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
  42. [gl_cv_func_malloc_posix],
  43. [
  44. dnl It is too dangerous to try to allocate a large amount of memory:
  45. dnl some systems go to their knees when you do that. So assume that
  46. dnl all Unix implementations of the function are POSIX compliant.
  47. AC_COMPILE_IFELSE(
  48. [AC_LANG_PROGRAM(
  49. [[]],
  50. [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  51. choke me
  52. #endif
  53. ]])],
  54. [gl_cv_func_malloc_posix=yes],
  55. [gl_cv_func_malloc_posix=no])
  56. ])
  57. ])