malloc.m4 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # malloc.m4 serial 9
  2. dnl Copyright (C) 2007, 2009 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_POSIX
  7. # --------------------
  8. # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
  9. # fails), and replace malloc if it is not.
  10. AC_DEFUN([gl_FUNC_MALLOC_POSIX],
  11. [
  12. AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
  13. if test $gl_cv_func_malloc_posix = yes; then
  14. HAVE_MALLOC_POSIX=1
  15. AC_DEFINE([HAVE_MALLOC_POSIX], [1],
  16. [Define if the 'malloc' function is POSIX compliant.])
  17. else
  18. AC_LIBOBJ([malloc])
  19. HAVE_MALLOC_POSIX=0
  20. fi
  21. AC_SUBST([HAVE_MALLOC_POSIX])
  22. ])
  23. # Test whether malloc, realloc, calloc are POSIX compliant,
  24. # Set gl_cv_func_malloc_posix to yes or no accordingly.
  25. AC_DEFUN([gl_CHECK_MALLOC_POSIX],
  26. [
  27. AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
  28. [gl_cv_func_malloc_posix],
  29. [
  30. dnl It is too dangerous to try to allocate a large amount of memory:
  31. dnl some systems go to their knees when you do that. So assume that
  32. dnl all Unix implementations of the function are POSIX compliant.
  33. AC_TRY_COMPILE([],
  34. [#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  35. choke me
  36. #endif
  37. ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
  38. ])
  39. ])