malloc.m4 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # malloc.m4 serial 10
  2. dnl Copyright (C) 2007, 2009, 2010 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], [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], [0])
  19. gl_REPLACE_MALLOC
  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. gl_REPLACE_MALLOC
  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_TRY_COMPILE([],
  48. [#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  49. choke me
  50. #endif
  51. ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
  52. ])
  53. ])
  54. AC_DEFUN([gl_REPLACE_MALLOC],
  55. [
  56. AC_LIBOBJ([malloc])
  57. REPLACE_MALLOC=1
  58. ])