mbsrtowcs.m4 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # mbsrtowcs.m4 serial 13
  2. dnl Copyright (C) 2008-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. AC_DEFUN([gl_FUNC_MBSRTOWCS],
  7. [
  8. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  9. AC_REQUIRE([AC_TYPE_MBSTATE_T])
  10. gl_MBSTATE_T_BROKEN
  11. AC_CHECK_FUNCS_ONCE([mbsrtowcs])
  12. if test $ac_cv_func_mbsrtowcs = no; then
  13. HAVE_MBSRTOWCS=0
  14. AC_CHECK_DECLS([mbsrtowcs],,, [[
  15. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  16. <wchar.h>.
  17. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  18. included before <wchar.h>. */
  19. #include <stddef.h>
  20. #include <stdio.h>
  21. #include <time.h>
  22. #include <wchar.h>
  23. ]])
  24. if test $ac_cv_have_decl_mbsrtowcs = yes; then
  25. dnl On Minix 3.1.8, the system's <wchar.h> declares mbsrtowcs() although
  26. dnl it does not have the function. Avoid a collision with gnulib's
  27. dnl replacement.
  28. REPLACE_MBSRTOWCS=1
  29. fi
  30. else
  31. if test $REPLACE_MBSTATE_T = 1; then
  32. REPLACE_MBSRTOWCS=1
  33. else
  34. gl_MBSRTOWCS_WORKS
  35. case "$gl_cv_func_mbsrtowcs_works" in
  36. *yes) ;;
  37. *) REPLACE_MBSRTOWCS=1 ;;
  38. esac
  39. fi
  40. fi
  41. ])
  42. dnl Test whether mbsrtowcs works.
  43. dnl Result is gl_cv_func_mbsrtowcs_works.
  44. AC_DEFUN([gl_MBSRTOWCS_WORKS],
  45. [
  46. AC_REQUIRE([AC_PROG_CC])
  47. AC_REQUIRE([gt_LOCALE_FR])
  48. AC_REQUIRE([gt_LOCALE_FR_UTF8])
  49. AC_REQUIRE([gt_LOCALE_JA])
  50. AC_REQUIRE([gt_LOCALE_ZH_CN])
  51. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  52. AC_CACHE_CHECK([whether mbsrtowcs works],
  53. [gl_cv_func_mbsrtowcs_works],
  54. [
  55. dnl Initial guess, used when cross-compiling or when no suitable locale
  56. dnl is present.
  57. changequote(,)dnl
  58. case "$host_os" in
  59. # Guess no on HP-UX, Solaris, mingw.
  60. hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
  61. # Guess yes otherwise.
  62. *) gl_cv_func_mbsrtowcs_works="guessing yes" ;;
  63. esac
  64. changequote([,])dnl
  65. if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
  66. AC_RUN_IFELSE(
  67. [AC_LANG_SOURCE([[
  68. #include <locale.h>
  69. #include <string.h>
  70. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  71. <wchar.h>.
  72. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  73. included before <wchar.h>. */
  74. #include <stddef.h>
  75. #include <stdio.h>
  76. #include <time.h>
  77. #include <wchar.h>
  78. int main ()
  79. {
  80. int result = 0;
  81. /* Test whether the function supports a NULL destination argument.
  82. This fails on native Windows. */
  83. if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
  84. {
  85. const char input[] = "\337er";
  86. const char *src = input;
  87. mbstate_t state;
  88. memset (&state, '\0', sizeof (mbstate_t));
  89. if (mbsrtowcs (NULL, &src, 1, &state) != 3
  90. || src != input)
  91. result |= 1;
  92. }
  93. /* Test whether the function works when started with a conversion state
  94. in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
  95. if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  96. {
  97. const char input[] = "B\303\274\303\237er";
  98. mbstate_t state;
  99. memset (&state, '\0', sizeof (mbstate_t));
  100. if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
  101. if (!mbsinit (&state))
  102. {
  103. const char *src = input + 2;
  104. if (mbsrtowcs (NULL, &src, 10, &state) != 4)
  105. result |= 2;
  106. }
  107. }
  108. if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  109. {
  110. const char input[] = "<\306\374\313\334\270\354>";
  111. mbstate_t state;
  112. memset (&state, '\0', sizeof (mbstate_t));
  113. if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
  114. if (!mbsinit (&state))
  115. {
  116. const char *src = input + 4;
  117. if (mbsrtowcs (NULL, &src, 10, &state) != 3)
  118. result |= 4;
  119. }
  120. }
  121. if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  122. {
  123. const char input[] = "B\250\271\201\060\211\070er";
  124. mbstate_t state;
  125. memset (&state, '\0', sizeof (mbstate_t));
  126. if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
  127. if (!mbsinit (&state))
  128. {
  129. const char *src = input + 2;
  130. if (mbsrtowcs (NULL, &src, 10, &state) != 4)
  131. result |= 8;
  132. }
  133. }
  134. return result;
  135. }]])],
  136. [gl_cv_func_mbsrtowcs_works=yes],
  137. [gl_cv_func_mbsrtowcs_works=no],
  138. [:])
  139. fi
  140. ])
  141. ])
  142. # Prerequisites of lib/mbsrtowcs.c.
  143. AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
  144. :
  145. ])