Debian Codegraph @

m4/wcrtomb.m4

raw
1 # wcrtomb.m4 serial 16
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.
6
7 AC_DEFUN([gl_FUNC_WCRTOMB],
8 [
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 gl_MBSTATE_T_BROKEN
13
14 AC_CHECK_FUNCS_ONCE([wcrtomb])
15 if test $ac_cv_func_wcrtomb = no; then
16 HAVE_WCRTOMB=0
17 AC_CHECK_DECLS([wcrtomb],,, [[
18 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
19 <wchar.h>.
20 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
21 included before <wchar.h>. */
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <time.h>
25 #include <wchar.h>
26 ]])
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
30 dnl replacement.
31 REPLACE_WCRTOMB=1
32 fi
33 else
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
37 dnl REPLACE_WCRTOMB=1
38 dnl fi
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],
51 [AC_RUN_IFELSE(
52 [AC_LANG_SOURCE([[
53 #include <string.h>
54 #include <stdlib.h>
55 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
56 <wchar.h>.
57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
58 included before <wchar.h>. */
59 #include <stddef.h>
60 #include <stdio.h>
61 #include <wchar.h>
62 int main ()
63 {
64 mbstate_t state;
65 char out[64];
66 int count;
67 memset (&state, 0, sizeof (state));
68 out[0] = 'x';
69 count = wcrtomb (out, L'a', &state);
70 return !(count == 1 && out[0] == 'a');
71 }]])],
72 [gl_cv_func_wcrtomb_works=yes],
73 [gl_cv_func_wcrtomb_works=no],
74 [case "$host_os" in
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";;
79 esac
80 ])
81 ])
82 case "$gl_cv_func_wcrtomb_works" in
83 *yes) ;;
84 *) AC_DEFINE([WCRTOMB_C_LOCALE_BUG], [1],
85 [Define if the wcrtomb function does not work in the C locale.])
86 REPLACE_WCRTOMB=1 ;;
87 esac
88 fi
89 if test $REPLACE_WCRTOMB = 0; then
90 AC_CACHE_CHECK([whether wcrtomb return value is correct],
91 [gl_cv_func_wcrtomb_retval],
92 [
93 dnl Initial guess, used when cross-compiling or when no suitable locale
94 dnl is present.
95 changequote(,)dnl
96 case "$host_os" in
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" ;;
101 esac
102 changequote([,])dnl
103 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
104 AC_RUN_IFELSE(
105 [AC_LANG_SOURCE([[
106 #include <locale.h>
107 #include <string.h>
108 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
109 <wchar.h>.
110 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
111 included before <wchar.h>. */
112 #include <stddef.h>
113 #include <stdio.h>
114 #include <time.h>
115 #include <wchar.h>
116 #include <stdlib.h>
117 int main ()
118 {
119 int result = 0;
120 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
121 {
122 if (wcrtomb (NULL, 0, NULL) != 1)
123 result |= 1;
124 }
125 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
126 {
127 if (wcrtomb (NULL, 0, NULL) != 1)
128 result |= 2;
129 {
130 wchar_t wc = (wchar_t) 0xBADFACE;
131 if (mbtowc (&wc, "\303\274", 2) == 2)
132 if (wcrtomb (NULL, wc, NULL) != 1)
133 result |= 2;
134 }
135 }
136 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
137 {
138 if (wcrtomb (NULL, 0, NULL) != 1)
139 result |= 4;
140 }
141 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
142 {
143 if (wcrtomb (NULL, 0, NULL) != 1)
144 result |= 8;
145 }
146 return result;
147 }]])],
148 [gl_cv_func_wcrtomb_retval=yes],
149 [gl_cv_func_wcrtomb_retval=no],
150 [:])
151 fi
152 ])
153 case "$gl_cv_func_wcrtomb_retval" in
154 *yes) ;;
155 *) AC_DEFINE([WCRTOMB_RETVAL_BUG], [1],
156 [Define if the wcrtomb function has an incorrect return value.])
157 REPLACE_WCRTOMB=1 ;;
158 esac
159 fi
160 fi
161 ])
162
163 # Prerequisites of lib/wcrtomb.c.
164 AC_DEFUN([gl_PREREQ_WCRTOMB], [
165 :
166 ])