funcs.m4 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
  2. # DPKG_FUNC_VA_COPY
  3. # -----------------
  4. # Define HAVE_VA_COPY if we have va_copy, fail if they can't be assigned
  5. AC_DEFUN([DPKG_FUNC_VA_COPY],
  6. [AC_CACHE_CHECK([for va_copy], [dpkg_cv_va_copy],
  7. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  8. [[#include <stdarg.h>
  9. int main()
  10. {
  11. va_list v1, v2;
  12. va_copy (v1, v2);
  13. exit (0);
  14. }
  15. ]])],
  16. [dpkg_cv_va_copy=yes],
  17. [dpkg_cv_va_copy=no],
  18. [dpkg_cv_va_copy=no])])
  19. AS_IF([test "x$dpkg_cv_va_copy" = "xyes"],
  20. [AC_DEFINE([HAVE_VA_COPY], 1,
  21. [Define to 1 if the 'va_copy' macro exists])])
  22. ])# DPKG_FUNC_VA_COPY
  23. # DPKG_FUNC_C99_SNPRINTF
  24. # -----------------------
  25. # Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
  26. AC_DEFUN([DPKG_FUNC_C99_SNPRINTF],
  27. [AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf],
  28. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  29. #include <stdarg.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. int test_vsnprintf(const char *fmt, ...)
  33. {
  34. int n;
  35. va_list ap;
  36. va_start(ap, fmt);
  37. n = vsnprintf(NULL, 0, fmt, ap);
  38. va_end(ap);
  39. return n;
  40. }
  41. int main()
  42. {
  43. int n;
  44. n = snprintf(NULL, 0, "format %s %d", "string", 10);
  45. if (n != strlen("format string 10"))
  46. return 1;
  47. n = test_vsnprintf("format %s %d", "string", 10);
  48. if (n != strlen("format string 10"))
  49. return 1;
  50. return 0;
  51. }
  52. ]])],
  53. [dpkg_cv_c99_snprintf=yes],
  54. [dpkg_cv_c99_snprintf=no],
  55. [dpkg_cv_c99_snprintf=no])])
  56. AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"],
  57. [AC_DEFINE([HAVE_C99_SNPRINTF], 1,
  58. [Define to 1 if the 'snprintf' family is C99 conformant])],
  59. )
  60. AM_CONDITIONAL(HAVE_C99_SNPRINTF, [test "x$dpkg_cv_c99_snprintf" = "xyes"])
  61. ])# DPKG_FUNC_C99_SNPRINTF
  62. # DPKG_CHECK_COMPAT_FUNCS(LIST)
  63. # -----------------------
  64. # Check each function and define an automake conditional
  65. AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS],
  66. [
  67. AC_CHECK_FUNCS([$1])
  68. m4_foreach_w([ac_func], [$1], [
  69. AM_CONDITIONAL(HAVE_[]AS_TR_CPP(ac_func),
  70. [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
  71. ])
  72. ]) # DPKG_CHECK_COMPAT_FUNCS