2 dnl Copyright (C) 2008-2020 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.
7 AC_DEFUN([gl_FUNC_WCRTOMB],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 AC_CHECK_FUNCS_ONCE([wcrtomb])
15 if test $ac_cv_func_wcrtomb = no; then
17 AC_CHECK_DECLS([wcrtomb],,, [[
18 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
20 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
21 included before <wchar.h>. */
27 if test $ac_cv_have_decl_wcrtomb = yes; then
28 dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
29 dnl it does not have the function. Avoid a collision with gnulib's
34 dnl We don't actually need to override wcrtomb when redefining the semantics
35 dnl of the mbstate_t type. Tested on 32-bit AIX.
36 dnl if test $REPLACE_MBSTATE_T = 1; then
39 if test $REPLACE_WCRTOMB = 0; then
40 dnl On Android 4.3, wcrtomb produces wrong characters in the C locale.
41 dnl On AIX 4.3, OSF/1 5.1 and Solaris <= 11.3, wcrtomb (NULL, 0, NULL)
42 dnl sometimes returns 0 instead of 1.
43 AC_REQUIRE([AC_PROG_CC])
44 AC_REQUIRE([gt_LOCALE_FR])
45 AC_REQUIRE([gt_LOCALE_FR_UTF8])
46 AC_REQUIRE([gt_LOCALE_JA])
47 AC_REQUIRE([gt_LOCALE_ZH_CN])
48 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
49 AC_CACHE_CHECK([whether wcrtomb works in the C locale],
50 [gl_cv_func_wcrtomb_works],
55 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
58 included before <wchar.h>. */
67 memset (&state, 0, sizeof (state));
69 count = wcrtomb (out, L'a', &state);
70 return !(count == 1 && out[0] == 'a');
72 [gl_cv_func_wcrtomb_works=yes],
73 [gl_cv_func_wcrtomb_works=no],
75 # Guess no on Android.
76 linux*-android*) gl_cv_func_wcrtomb_works="guessing no";;
77 # Guess yes otherwise.
78 *) gl_cv_func_wcrtomb_works="guessing yes";;
82 case "$gl_cv_func_wcrtomb_works" in
84 *) AC_DEFINE([WCRTOMB_C_LOCALE_BUG], [1],
85 [Define if the wcrtomb function does not work in the C locale.])
89 if test $REPLACE_WCRTOMB = 0; then
90 AC_CACHE_CHECK([whether wcrtomb return value is correct],
91 [gl_cv_func_wcrtomb_retval],
93 dnl Initial guess, used when cross-compiling or when no suitable locale
97 # Guess no on AIX 4, OSF/1, Solaris, native Windows.
98 aix4* | osf* | solaris* | mingw*) gl_cv_func_wcrtomb_retval="guessing no" ;;
99 # Guess yes otherwise.
100 *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
103 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
108 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
110 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
111 included before <wchar.h>. */
120 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
122 if (wcrtomb (NULL, 0, NULL) != 1)
125 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
127 if (wcrtomb (NULL, 0, NULL) != 1)
130 wchar_t wc = (wchar_t) 0xBADFACE;
131 if (mbtowc (&wc, "\303\274", 2) == 2)
132 if (wcrtomb (NULL, wc, NULL) != 1)
136 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
138 if (wcrtomb (NULL, 0, NULL) != 1)
141 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
143 if (wcrtomb (NULL, 0, NULL) != 1)
148 [gl_cv_func_wcrtomb_retval=yes],
149 [gl_cv_func_wcrtomb_retval=no],
153 case "$gl_cv_func_wcrtomb_retval" in
155 *) AC_DEFINE([WCRTOMB_RETVAL_BUG], [1],
156 [Define if the wcrtomb function has an incorrect return value.])
163 # Prerequisites of lib/wcrtomb.c.
164 AC_DEFUN([gl_PREREQ_WCRTOMB], [