wcrtomb.m4 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # wcrtomb.m4 serial 17
  2. dnl Copyright (C) 2008-2023 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_WCRTOMB],
  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([wcrtomb])
  12. if test $ac_cv_func_wcrtomb = no; then
  13. HAVE_WCRTOMB=0
  14. AC_CHECK_DECLS([wcrtomb],,, [[
  15. #include <wchar.h>
  16. ]])
  17. if test $ac_cv_have_decl_wcrtomb = yes; then
  18. dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
  19. dnl it does not have the function. Avoid a collision with gnulib's
  20. dnl replacement.
  21. REPLACE_WCRTOMB=1
  22. fi
  23. else
  24. dnl We don't actually need to override wcrtomb when redefining the semantics
  25. dnl of the mbstate_t type. Tested on 32-bit AIX.
  26. dnl if test $REPLACE_MBSTATE_T = 1; then
  27. dnl REPLACE_WCRTOMB=1
  28. dnl fi
  29. if test $REPLACE_WCRTOMB = 0; then
  30. dnl On Android 4.3, wcrtomb produces wrong characters in the C locale.
  31. dnl On AIX 4.3, OSF/1 5.1 and Solaris <= 11.3, wcrtomb (NULL, 0, NULL)
  32. dnl sometimes returns 0 instead of 1.
  33. AC_REQUIRE([AC_PROG_CC])
  34. AC_REQUIRE([gt_LOCALE_FR])
  35. AC_REQUIRE([gt_LOCALE_FR_UTF8])
  36. AC_REQUIRE([gt_LOCALE_JA])
  37. AC_REQUIRE([gt_LOCALE_ZH_CN])
  38. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  39. AC_CACHE_CHECK([whether wcrtomb works in the C locale],
  40. [gl_cv_func_wcrtomb_works],
  41. [AC_RUN_IFELSE(
  42. [AC_LANG_SOURCE([[
  43. #include <string.h>
  44. #include <stdlib.h>
  45. #include <wchar.h>
  46. int main ()
  47. {
  48. mbstate_t state;
  49. char out[64];
  50. int count;
  51. memset (&state, 0, sizeof (state));
  52. out[0] = 'x';
  53. count = wcrtomb (out, L'a', &state);
  54. return !(count == 1 && out[0] == 'a');
  55. }]])],
  56. [gl_cv_func_wcrtomb_works=yes],
  57. [gl_cv_func_wcrtomb_works=no],
  58. [case "$host_os" in
  59. # Guess no on Android.
  60. linux*-android*) gl_cv_func_wcrtomb_works="guessing no";;
  61. # Guess yes otherwise.
  62. *) gl_cv_func_wcrtomb_works="guessing yes";;
  63. esac
  64. ])
  65. ])
  66. case "$gl_cv_func_wcrtomb_works" in
  67. *yes) ;;
  68. *) AC_DEFINE([WCRTOMB_C_LOCALE_BUG], [1],
  69. [Define if the wcrtomb function does not work in the C locale.])
  70. REPLACE_WCRTOMB=1 ;;
  71. esac
  72. fi
  73. if test $REPLACE_WCRTOMB = 0; then
  74. AC_CACHE_CHECK([whether wcrtomb return value is correct],
  75. [gl_cv_func_wcrtomb_retval],
  76. [
  77. dnl Initial guess, used when cross-compiling or when no suitable locale
  78. dnl is present.
  79. changequote(,)dnl
  80. case "$host_os" in
  81. # Guess no on AIX 4, OSF/1, Solaris, native Windows.
  82. aix4* | osf* | solaris* | mingw*) gl_cv_func_wcrtomb_retval="guessing no" ;;
  83. # Guess yes otherwise.
  84. *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
  85. esac
  86. changequote([,])dnl
  87. if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
  88. AC_RUN_IFELSE(
  89. [AC_LANG_SOURCE([[
  90. #include <locale.h>
  91. #include <string.h>
  92. #include <wchar.h>
  93. #include <stdlib.h>
  94. int main ()
  95. {
  96. int result = 0;
  97. if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
  98. {
  99. if (wcrtomb (NULL, 0, NULL) != 1)
  100. result |= 1;
  101. }
  102. if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  103. {
  104. if (wcrtomb (NULL, 0, NULL) != 1)
  105. result |= 2;
  106. {
  107. wchar_t wc = (wchar_t) 0xBADFACE;
  108. if (mbtowc (&wc, "\303\274", 2) == 2)
  109. if (wcrtomb (NULL, wc, NULL) != 1)
  110. result |= 2;
  111. }
  112. }
  113. if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  114. {
  115. if (wcrtomb (NULL, 0, NULL) != 1)
  116. result |= 4;
  117. }
  118. if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  119. {
  120. if (wcrtomb (NULL, 0, NULL) != 1)
  121. result |= 8;
  122. }
  123. return result;
  124. }]])],
  125. [gl_cv_func_wcrtomb_retval=yes],
  126. [gl_cv_func_wcrtomb_retval=no],
  127. [:])
  128. fi
  129. ])
  130. case "$gl_cv_func_wcrtomb_retval" in
  131. *yes) ;;
  132. *) AC_DEFINE([WCRTOMB_RETVAL_BUG], [1],
  133. [Define if the wcrtomb function has an incorrect return value.])
  134. REPLACE_WCRTOMB=1 ;;
  135. esac
  136. fi
  137. fi
  138. ])
  139. # Prerequisites of lib/wcrtomb.c.
  140. AC_DEFUN([gl_PREREQ_WCRTOMB], [
  141. :
  142. ])