1 | # mbrlen.m4 serial 8
|
---|
2 | dnl Copyright (C) 2008, 2010-2012 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_MBRLEN],
|
---|
8 | [
|
---|
9 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
|
---|
10 |
|
---|
11 | AC_REQUIRE([AC_TYPE_MBSTATE_T])
|
---|
12 | AC_REQUIRE([gl_FUNC_MBRTOWC])
|
---|
13 | AC_CHECK_FUNCS_ONCE([mbrlen])
|
---|
14 | if test $ac_cv_func_mbrlen = no; then
|
---|
15 | HAVE_MBRLEN=0
|
---|
16 | AC_CHECK_DECLS([mbrlen],,, [[
|
---|
17 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
|
---|
18 | <wchar.h>.
|
---|
19 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
---|
20 | included before <wchar.h>. */
|
---|
21 | #include <stddef.h>
|
---|
22 | #include <stdio.h>
|
---|
23 | #include <time.h>
|
---|
24 | #include <wchar.h>
|
---|
25 | ]])
|
---|
26 | if test $ac_cv_have_decl_mbrlen = yes; then
|
---|
27 | dnl On Minix 3.1.8, the system's <wchar.h> declares mbrlen() although
|
---|
28 | dnl it does not have the function. Avoid a collision with gnulib's
|
---|
29 | dnl replacement.
|
---|
30 | REPLACE_MBRLEN=1
|
---|
31 | fi
|
---|
32 | else
|
---|
33 | dnl Most bugs affecting the system's mbrtowc function also affect the
|
---|
34 | dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
|
---|
35 | dnl We could also run the individual tests below; the results would be
|
---|
36 | dnl the same.
|
---|
37 | if test $REPLACE_MBRTOWC = 1; then
|
---|
38 | REPLACE_MBRLEN=1
|
---|
39 | fi
|
---|
40 | fi
|
---|
41 | ])
|
---|
42 |
|
---|
43 | dnl Test whether mbrlen puts the state into non-initial state when parsing an
|
---|
44 | dnl incomplete multibyte character.
|
---|
45 | dnl Result is gl_cv_func_mbrlen_incomplete_state.
|
---|
46 |
|
---|
47 | AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
|
---|
48 | [
|
---|
49 | AC_REQUIRE([AC_PROG_CC])
|
---|
50 | AC_REQUIRE([gt_LOCALE_JA])
|
---|
51 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
---|
52 | AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
|
---|
53 | [gl_cv_func_mbrlen_incomplete_state],
|
---|
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 AIX and OSF/1.
|
---|
60 | aix* | osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
|
---|
61 | # Guess yes otherwise.
|
---|
62 | *) gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
|
---|
63 | esac
|
---|
64 | changequote([,])dnl
|
---|
65 | if test $LOCALE_JA != 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 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
|
---|
81 | {
|
---|
82 | const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
|
---|
83 | mbstate_t state;
|
---|
84 |
|
---|
85 | memset (&state, '\0', sizeof (mbstate_t));
|
---|
86 | if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
|
---|
87 | if (mbsinit (&state))
|
---|
88 | return 1;
|
---|
89 | }
|
---|
90 | return 0;
|
---|
91 | }]])],
|
---|
92 | [gl_cv_func_mbrlen_incomplete_state=yes],
|
---|
93 | [gl_cv_func_mbrlen_incomplete_state=no],
|
---|
94 | [])
|
---|
95 | fi
|
---|
96 | ])
|
---|
97 | ])
|
---|
98 |
|
---|
99 | dnl Test whether mbrlen, when parsing the end of a multibyte character,
|
---|
100 | dnl correctly returns the number of bytes that were needed to complete the
|
---|
101 | dnl character (not the total number of bytes of the multibyte character).
|
---|
102 | dnl Result is gl_cv_func_mbrlen_retval.
|
---|
103 |
|
---|
104 | AC_DEFUN([gl_MBRLEN_RETVAL],
|
---|
105 | [
|
---|
106 | AC_REQUIRE([AC_PROG_CC])
|
---|
107 | AC_REQUIRE([gt_LOCALE_FR_UTF8])
|
---|
108 | AC_REQUIRE([gt_LOCALE_JA])
|
---|
109 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
---|
110 | AC_CACHE_CHECK([whether mbrlen has a correct return value],
|
---|
111 | [gl_cv_func_mbrlen_retval],
|
---|
112 | [
|
---|
113 | dnl Initial guess, used when cross-compiling or when no suitable locale
|
---|
114 | dnl is present.
|
---|
115 | changequote(,)dnl
|
---|
116 | case "$host_os" in
|
---|
117 | # Guess no on HP-UX and Solaris.
|
---|
118 | hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
|
---|
119 | # Guess yes otherwise.
|
---|
120 | *) gl_cv_func_mbrlen_retval="guessing yes" ;;
|
---|
121 | esac
|
---|
122 | changequote([,])dnl
|
---|
123 | if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
|
---|
124 | AC_RUN_IFELSE(
|
---|
125 | [AC_LANG_SOURCE([[
|
---|
126 | #include <locale.h>
|
---|
127 | #include <string.h>
|
---|
128 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
|
---|
129 | <wchar.h>.
|
---|
130 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
---|
131 | included before <wchar.h>. */
|
---|
132 | #include <stddef.h>
|
---|
133 | #include <stdio.h>
|
---|
134 | #include <time.h>
|
---|
135 | #include <wchar.h>
|
---|
136 | int main ()
|
---|
137 | {
|
---|
138 | int result = 0;
|
---|
139 | /* This fails on Solaris. */
|
---|
140 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
|
---|
141 | {
|
---|
142 | char input[] = "B\303\274\303\237er"; /* "Büßer" */
|
---|
143 | mbstate_t state;
|
---|
144 |
|
---|
145 | memset (&state, '\0', sizeof (mbstate_t));
|
---|
146 | if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
|
---|
147 | {
|
---|
148 | input[1] = '\0';
|
---|
149 | if (mbrlen (input + 2, 5, &state) != 1)
|
---|
150 | result |= 1;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | /* This fails on HP-UX 11.11. */
|
---|
154 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
|
---|
155 | {
|
---|
156 | char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
|
---|
157 | mbstate_t state;
|
---|
158 |
|
---|
159 | memset (&state, '\0', sizeof (mbstate_t));
|
---|
160 | if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
|
---|
161 | {
|
---|
162 | input[1] = '\0';
|
---|
163 | if (mbrlen (input + 2, 5, &state) != 2)
|
---|
164 | result |= 2;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | return result;
|
---|
168 | }]])],
|
---|
169 | [gl_cv_func_mbrlen_retval=yes],
|
---|
170 | [gl_cv_func_mbrlen_retval=no],
|
---|
171 | [])
|
---|
172 | fi
|
---|
173 | ])
|
---|
174 | ])
|
---|
175 |
|
---|
176 | dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
|
---|
177 | dnl Result is gl_cv_func_mbrlen_nul_retval.
|
---|
178 |
|
---|
179 | AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
|
---|
180 | [
|
---|
181 | AC_REQUIRE([AC_PROG_CC])
|
---|
182 | AC_REQUIRE([gt_LOCALE_ZH_CN])
|
---|
183 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
---|
184 | AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
|
---|
185 | [gl_cv_func_mbrlen_nul_retval],
|
---|
186 | [
|
---|
187 | dnl Initial guess, used when cross-compiling or when no suitable locale
|
---|
188 | dnl is present.
|
---|
189 | changequote(,)dnl
|
---|
190 | case "$host_os" in
|
---|
191 | # Guess no on Solaris 9.
|
---|
192 | solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
|
---|
193 | # Guess yes otherwise.
|
---|
194 | *) gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
|
---|
195 | esac
|
---|
196 | changequote([,])dnl
|
---|
197 | if test $LOCALE_ZH_CN != none; then
|
---|
198 | AC_RUN_IFELSE(
|
---|
199 | [AC_LANG_SOURCE([[
|
---|
200 | #include <locale.h>
|
---|
201 | #include <string.h>
|
---|
202 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
|
---|
203 | <wchar.h>.
|
---|
204 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
---|
205 | included before <wchar.h>. */
|
---|
206 | #include <stddef.h>
|
---|
207 | #include <stdio.h>
|
---|
208 | #include <time.h>
|
---|
209 | #include <wchar.h>
|
---|
210 | int main ()
|
---|
211 | {
|
---|
212 | /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030. */
|
---|
213 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
|
---|
214 | {
|
---|
215 | mbstate_t state;
|
---|
216 |
|
---|
217 | memset (&state, '\0', sizeof (mbstate_t));
|
---|
218 | if (mbrlen ("", 1, &state) != 0)
|
---|
219 | return 1;
|
---|
220 | }
|
---|
221 | return 0;
|
---|
222 | }]])],
|
---|
223 | [gl_cv_func_mbrlen_nul_retval=yes],
|
---|
224 | [gl_cv_func_mbrlen_nul_retval=no],
|
---|
225 | [])
|
---|
226 | fi
|
---|
227 | ])
|
---|
228 | ])
|
---|
229 |
|
---|
230 | # Prerequisites of lib/mbrlen.c.
|
---|
231 | AC_DEFUN([gl_PREREQ_MBRLEN], [
|
---|
232 | :
|
---|
233 | ])
|
---|