Commit | Line | Data |
---|---|---|
c0c3707f CB |
1 | # mbrtowc.m4 serial 33 -*- coding: utf-8 -*- |
2 | dnl Copyright (C) 2001-2002, 2004-2005, 2008-2019 Free Software Foundation, | |
8690e634 JK |
3 | dnl Inc. |
4 | dnl This file is free software; the Free Software Foundation | |
5 | dnl gives unlimited permission to copy and/or distribute it, | |
6 | dnl with or without modifications, as long as this notice is preserved. | |
7 | ||
8 | AC_DEFUN([gl_FUNC_MBRTOWC], | |
9 | [ | |
10 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) | |
11 | ||
12 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) | |
13 | gl_MBSTATE_T_BROKEN | |
14 | ||
15 | AC_CHECK_FUNCS_ONCE([mbrtowc]) | |
16 | if test $ac_cv_func_mbrtowc = no; then | |
17 | HAVE_MBRTOWC=0 | |
18 | AC_CHECK_DECLS([mbrtowc],,, [[ | |
19 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
20 | <wchar.h>. | |
21 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
22 | included before <wchar.h>. */ | |
23 | #include <stddef.h> | |
24 | #include <stdio.h> | |
25 | #include <time.h> | |
26 | #include <wchar.h> | |
27 | ]]) | |
28 | if test $ac_cv_have_decl_mbrtowc = yes; then | |
29 | dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although | |
30 | dnl it does not have the function. Avoid a collision with gnulib's | |
31 | dnl replacement. | |
32 | REPLACE_MBRTOWC=1 | |
33 | fi | |
34 | else | |
35 | if test $REPLACE_MBSTATE_T = 1; then | |
36 | REPLACE_MBRTOWC=1 | |
37 | else | |
38 | gl_MBRTOWC_NULL_ARG1 | |
39 | gl_MBRTOWC_NULL_ARG2 | |
40 | gl_MBRTOWC_RETVAL | |
41 | gl_MBRTOWC_NUL_RETVAL | |
4a626d0a | 42 | gl_MBRTOWC_EMPTY_INPUT |
49e4877c | 43 | gl_MBRTOWC_C_LOCALE |
8690e634 JK |
44 | case "$gl_cv_func_mbrtowc_null_arg1" in |
45 | *yes) ;; | |
46 | *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1], | |
47 | [Define if the mbrtowc function has the NULL pwc argument bug.]) | |
48 | REPLACE_MBRTOWC=1 | |
49 | ;; | |
50 | esac | |
51 | case "$gl_cv_func_mbrtowc_null_arg2" in | |
52 | *yes) ;; | |
53 | *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1], | |
54 | [Define if the mbrtowc function has the NULL string argument bug.]) | |
55 | REPLACE_MBRTOWC=1 | |
56 | ;; | |
57 | esac | |
58 | case "$gl_cv_func_mbrtowc_retval" in | |
59 | *yes) ;; | |
60 | *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], | |
61 | [Define if the mbrtowc function returns a wrong return value.]) | |
62 | REPLACE_MBRTOWC=1 | |
63 | ;; | |
64 | esac | |
65 | case "$gl_cv_func_mbrtowc_nul_retval" in | |
66 | *yes) ;; | |
67 | *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1], | |
68 | [Define if the mbrtowc function does not return 0 for a NUL character.]) | |
69 | REPLACE_MBRTOWC=1 | |
70 | ;; | |
71 | esac | |
4a626d0a PA |
72 | case "$gl_cv_func_mbrtowc_empty_input" in |
73 | *yes) ;; | |
74 | *) AC_DEFINE([MBRTOWC_EMPTY_INPUT_BUG], [1], | |
75 | [Define if the mbrtowc function does not return (size_t) -2 | |
76 | for empty input.]) | |
77 | REPLACE_MBRTOWC=1 | |
78 | ;; | |
79 | esac | |
49e4877c PA |
80 | case $gl_cv_C_locale_sans_EILSEQ in |
81 | *yes) ;; | |
82 | *) AC_DEFINE([C_LOCALE_MAYBE_EILSEQ], [1], | |
83 | [Define to 1 if the C locale may have encoding errors.]) | |
84 | REPLACE_MBRTOWC=1 | |
85 | ;; | |
86 | esac | |
8690e634 JK |
87 | fi |
88 | fi | |
89 | ]) | |
90 | ||
91 | dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that | |
92 | dnl redefines the semantics of the given mbstate_t type. | |
93 | dnl Result is REPLACE_MBSTATE_T. | |
94 | dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to | |
95 | dnl avoid inconsistencies. | |
96 | ||
97 | AC_DEFUN([gl_MBSTATE_T_BROKEN], | |
98 | [ | |
99 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) | |
100 | ||
101 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) | |
102 | AC_CHECK_FUNCS_ONCE([mbsinit]) | |
103 | AC_CHECK_FUNCS_ONCE([mbrtowc]) | |
104 | if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then | |
105 | gl_MBRTOWC_INCOMPLETE_STATE | |
106 | gl_MBRTOWC_SANITYCHECK | |
107 | REPLACE_MBSTATE_T=0 | |
108 | case "$gl_cv_func_mbrtowc_incomplete_state" in | |
109 | *yes) ;; | |
110 | *) REPLACE_MBSTATE_T=1 ;; | |
111 | esac | |
112 | case "$gl_cv_func_mbrtowc_sanitycheck" in | |
113 | *yes) ;; | |
114 | *) REPLACE_MBSTATE_T=1 ;; | |
115 | esac | |
116 | else | |
117 | REPLACE_MBSTATE_T=1 | |
118 | fi | |
119 | ]) | |
120 | ||
121 | dnl Test whether mbrtowc puts the state into non-initial state when parsing an | |
122 | dnl incomplete multibyte character. | |
123 | dnl Result is gl_cv_func_mbrtowc_incomplete_state. | |
124 | ||
125 | AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE], | |
126 | [ | |
127 | AC_REQUIRE([AC_PROG_CC]) | |
128 | AC_REQUIRE([gt_LOCALE_JA]) | |
c0c3707f | 129 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) |
8690e634 JK |
130 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
131 | AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], | |
132 | [gl_cv_func_mbrtowc_incomplete_state], | |
133 | [ | |
134 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
135 | dnl is present. | |
136 | changequote(,)dnl | |
137 | case "$host_os" in | |
138 | # Guess no on AIX and OSF/1. | |
139 | aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;; | |
140 | # Guess yes otherwise. | |
141 | *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;; | |
142 | esac | |
143 | changequote([,])dnl | |
144 | if test $LOCALE_JA != none; then | |
145 | AC_RUN_IFELSE( | |
146 | [AC_LANG_SOURCE([[ | |
147 | #include <locale.h> | |
148 | #include <string.h> | |
149 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
150 | <wchar.h>. | |
151 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
152 | included before <wchar.h>. */ | |
153 | #include <stddef.h> | |
154 | #include <stdio.h> | |
155 | #include <time.h> | |
156 | #include <wchar.h> | |
157 | int main () | |
158 | { | |
159 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) | |
160 | { | |
161 | const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ | |
162 | mbstate_t state; | |
163 | wchar_t wc; | |
164 | ||
165 | memset (&state, '\0', sizeof (mbstate_t)); | |
166 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | |
167 | if (mbsinit (&state)) | |
c0c3707f | 168 | return 2; |
8690e634 JK |
169 | } |
170 | return 0; | |
171 | }]])], | |
172 | [gl_cv_func_mbrtowc_incomplete_state=yes], | |
173 | [gl_cv_func_mbrtowc_incomplete_state=no], | |
174 | [:]) | |
c0c3707f CB |
175 | else |
176 | if test $LOCALE_FR_UTF8 != none; then | |
177 | AC_RUN_IFELSE( | |
178 | [AC_LANG_SOURCE([[ | |
179 | #include <locale.h> | |
180 | #include <string.h> | |
181 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
182 | <wchar.h>. | |
183 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
184 | included before <wchar.h>. */ | |
185 | #include <stddef.h> | |
186 | #include <stdio.h> | |
187 | #include <time.h> | |
188 | #include <wchar.h> | |
189 | int main () | |
190 | { | |
191 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | |
192 | { | |
193 | const char input[] = "B\303\274\303\237er"; /* "Büßer" */ | |
194 | mbstate_t state; | |
195 | wchar_t wc; | |
196 | ||
197 | memset (&state, '\0', sizeof (mbstate_t)); | |
198 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | |
199 | if (mbsinit (&state)) | |
200 | return 2; | |
201 | } | |
202 | return 0; | |
203 | }]])], | |
204 | [gl_cv_func_mbrtowc_incomplete_state=yes], | |
205 | [gl_cv_func_mbrtowc_incomplete_state=no], | |
206 | [:]) | |
207 | fi | |
8690e634 JK |
208 | fi |
209 | ]) | |
210 | ]) | |
211 | ||
212 | dnl Test whether mbrtowc works not worse than mbtowc. | |
213 | dnl Result is gl_cv_func_mbrtowc_sanitycheck. | |
214 | ||
215 | AC_DEFUN([gl_MBRTOWC_SANITYCHECK], | |
216 | [ | |
217 | AC_REQUIRE([AC_PROG_CC]) | |
218 | AC_REQUIRE([gt_LOCALE_ZH_CN]) | |
219 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
220 | AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc], | |
221 | [gl_cv_func_mbrtowc_sanitycheck], | |
222 | [ | |
223 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
224 | dnl is present. | |
225 | changequote(,)dnl | |
226 | case "$host_os" in | |
227 | # Guess no on Solaris 8. | |
228 | solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;; | |
229 | # Guess yes otherwise. | |
230 | *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;; | |
231 | esac | |
232 | changequote([,])dnl | |
233 | if test $LOCALE_ZH_CN != none; then | |
234 | AC_RUN_IFELSE( | |
235 | [AC_LANG_SOURCE([[ | |
236 | #include <locale.h> | |
237 | #include <stdlib.h> | |
238 | #include <string.h> | |
239 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
240 | <wchar.h>. | |
241 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
242 | included before <wchar.h>. */ | |
243 | #include <stddef.h> | |
244 | #include <stdio.h> | |
245 | #include <time.h> | |
246 | #include <wchar.h> | |
247 | int main () | |
248 | { | |
249 | /* This fails on Solaris 8: | |
250 | mbrtowc returns 2, and sets wc to 0x00F0. | |
251 | mbtowc returns 4 (correct) and sets wc to 0x5EDC. */ | |
252 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) | |
253 | { | |
254 | char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ | |
255 | mbstate_t state; | |
256 | wchar_t wc; | |
257 | ||
258 | memset (&state, '\0', sizeof (mbstate_t)); | |
259 | if (mbrtowc (&wc, input + 3, 6, &state) != 4 | |
260 | && mbtowc (&wc, input + 3, 6) == 4) | |
c0c3707f | 261 | return 2; |
8690e634 JK |
262 | } |
263 | return 0; | |
264 | }]])], | |
265 | [gl_cv_func_mbrtowc_sanitycheck=yes], | |
266 | [gl_cv_func_mbrtowc_sanitycheck=no], | |
267 | [:]) | |
268 | fi | |
269 | ]) | |
270 | ]) | |
271 | ||
272 | dnl Test whether mbrtowc supports a NULL pwc argument correctly. | |
273 | dnl Result is gl_cv_func_mbrtowc_null_arg1. | |
274 | ||
275 | AC_DEFUN([gl_MBRTOWC_NULL_ARG1], | |
276 | [ | |
277 | AC_REQUIRE([AC_PROG_CC]) | |
278 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) | |
279 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
280 | AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument], | |
281 | [gl_cv_func_mbrtowc_null_arg1], | |
282 | [ | |
283 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
284 | dnl is present. | |
285 | changequote(,)dnl | |
286 | case "$host_os" in | |
287 | # Guess no on Solaris. | |
288 | solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;; | |
289 | # Guess yes otherwise. | |
290 | *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;; | |
291 | esac | |
292 | changequote([,])dnl | |
293 | if test $LOCALE_FR_UTF8 != none; then | |
294 | AC_RUN_IFELSE( | |
295 | [AC_LANG_SOURCE([[ | |
296 | #include <locale.h> | |
297 | #include <stdlib.h> | |
298 | #include <string.h> | |
299 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
300 | <wchar.h>. | |
301 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
302 | included before <wchar.h>. */ | |
303 | #include <stddef.h> | |
304 | #include <stdio.h> | |
305 | #include <time.h> | |
306 | #include <wchar.h> | |
307 | int main () | |
308 | { | |
309 | int result = 0; | |
310 | ||
311 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | |
312 | { | |
313 | char input[] = "\303\237er"; | |
314 | mbstate_t state; | |
315 | wchar_t wc; | |
316 | size_t ret; | |
317 | ||
318 | memset (&state, '\0', sizeof (mbstate_t)); | |
319 | wc = (wchar_t) 0xBADFACE; | |
320 | ret = mbrtowc (&wc, input, 5, &state); | |
321 | if (ret != 2) | |
322 | result |= 1; | |
323 | if (!mbsinit (&state)) | |
324 | result |= 2; | |
325 | ||
326 | memset (&state, '\0', sizeof (mbstate_t)); | |
327 | ret = mbrtowc (NULL, input, 5, &state); | |
328 | if (ret != 2) /* Solaris 7 fails here: ret is -1. */ | |
329 | result |= 4; | |
330 | if (!mbsinit (&state)) | |
331 | result |= 8; | |
332 | } | |
333 | return result; | |
334 | }]])], | |
335 | [gl_cv_func_mbrtowc_null_arg1=yes], | |
336 | [gl_cv_func_mbrtowc_null_arg1=no], | |
337 | [:]) | |
338 | fi | |
339 | ]) | |
340 | ]) | |
341 | ||
342 | dnl Test whether mbrtowc supports a NULL string argument correctly. | |
343 | dnl Result is gl_cv_func_mbrtowc_null_arg2. | |
344 | ||
345 | AC_DEFUN([gl_MBRTOWC_NULL_ARG2], | |
346 | [ | |
347 | AC_REQUIRE([AC_PROG_CC]) | |
348 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) | |
349 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
350 | AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument], | |
351 | [gl_cv_func_mbrtowc_null_arg2], | |
352 | [ | |
353 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
354 | dnl is present. | |
355 | changequote(,)dnl | |
356 | case "$host_os" in | |
357 | # Guess no on OSF/1. | |
358 | osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;; | |
359 | # Guess yes otherwise. | |
360 | *) gl_cv_func_mbrtowc_null_arg2="guessing yes" ;; | |
361 | esac | |
362 | changequote([,])dnl | |
363 | if test $LOCALE_FR_UTF8 != none; then | |
364 | AC_RUN_IFELSE( | |
365 | [AC_LANG_SOURCE([[ | |
366 | #include <locale.h> | |
367 | #include <string.h> | |
368 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
369 | <wchar.h>. | |
370 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
371 | included before <wchar.h>. */ | |
372 | #include <stddef.h> | |
373 | #include <stdio.h> | |
374 | #include <time.h> | |
375 | #include <wchar.h> | |
376 | int main () | |
377 | { | |
378 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | |
379 | { | |
380 | mbstate_t state; | |
381 | wchar_t wc; | |
382 | int ret; | |
383 | ||
384 | memset (&state, '\0', sizeof (mbstate_t)); | |
385 | wc = (wchar_t) 0xBADFACE; | |
386 | mbrtowc (&wc, NULL, 5, &state); | |
387 | /* Check that wc was not modified. */ | |
388 | if (wc != (wchar_t) 0xBADFACE) | |
c0c3707f | 389 | return 2; |
8690e634 JK |
390 | } |
391 | return 0; | |
392 | }]])], | |
393 | [gl_cv_func_mbrtowc_null_arg2=yes], | |
394 | [gl_cv_func_mbrtowc_null_arg2=no], | |
395 | [:]) | |
396 | fi | |
397 | ]) | |
398 | ]) | |
399 | ||
400 | dnl Test whether mbrtowc, when parsing the end of a multibyte character, | |
401 | dnl correctly returns the number of bytes that were needed to complete the | |
402 | dnl character (not the total number of bytes of the multibyte character). | |
403 | dnl Result is gl_cv_func_mbrtowc_retval. | |
404 | ||
405 | AC_DEFUN([gl_MBRTOWC_RETVAL], | |
406 | [ | |
407 | AC_REQUIRE([AC_PROG_CC]) | |
408 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) | |
409 | AC_REQUIRE([gt_LOCALE_JA]) | |
410 | AC_REQUIRE([AC_CANONICAL_HOST]) | |
411 | AC_CACHE_CHECK([whether mbrtowc has a correct return value], | |
412 | [gl_cv_func_mbrtowc_retval], | |
413 | [ | |
414 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
415 | dnl is present. | |
416 | changequote(,)dnl | |
417 | case "$host_os" in | |
418 | # Guess no on HP-UX, Solaris, native Windows. | |
419 | hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;; | |
420 | # Guess yes otherwise. | |
421 | *) gl_cv_func_mbrtowc_retval="guessing yes" ;; | |
422 | esac | |
423 | changequote([,])dnl | |
424 | if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \ | |
425 | || { case "$host_os" in mingw*) true;; *) false;; esac; }; then | |
426 | AC_RUN_IFELSE( | |
427 | [AC_LANG_SOURCE([[ | |
428 | #include <locale.h> | |
429 | #include <string.h> | |
430 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
431 | <wchar.h>. | |
432 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
433 | included before <wchar.h>. */ | |
434 | #include <stddef.h> | |
435 | #include <stdio.h> | |
436 | #include <time.h> | |
437 | #include <wchar.h> | |
438 | int main () | |
439 | { | |
440 | int result = 0; | |
441 | int found_some_locale = 0; | |
442 | /* This fails on Solaris. */ | |
443 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | |
444 | { | |
445 | char input[] = "B\303\274\303\237er"; /* "Büßer" */ | |
446 | mbstate_t state; | |
447 | wchar_t wc; | |
448 | ||
449 | memset (&state, '\0', sizeof (mbstate_t)); | |
450 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | |
451 | { | |
452 | input[1] = '\0'; | |
453 | if (mbrtowc (&wc, input + 2, 5, &state) != 1) | |
454 | result |= 1; | |
455 | } | |
456 | found_some_locale = 1; | |
457 | } | |
458 | /* This fails on HP-UX 11.11. */ | |
459 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) | |
460 | { | |
461 | char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ | |
462 | mbstate_t state; | |
463 | wchar_t wc; | |
464 | ||
465 | memset (&state, '\0', sizeof (mbstate_t)); | |
466 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | |
467 | { | |
468 | input[1] = '\0'; | |
469 | if (mbrtowc (&wc, input + 2, 5, &state) != 2) | |
470 | result |= 2; | |
471 | } | |
472 | found_some_locale = 1; | |
473 | } | |
474 | /* This fails on native Windows. */ | |
475 | if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL) | |
476 | { | |
477 | char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */ | |
478 | mbstate_t state; | |
479 | wchar_t wc; | |
480 | ||
481 | memset (&state, '\0', sizeof (mbstate_t)); | |
482 | if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) | |
483 | { | |
484 | input[3] = '\0'; | |
485 | if (mbrtowc (&wc, input + 4, 4, &state) != 1) | |
486 | result |= 4; | |
487 | } | |
488 | found_some_locale = 1; | |
489 | } | |
490 | if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL) | |
491 | { | |
492 | char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */ | |
493 | mbstate_t state; | |
494 | wchar_t wc; | |
495 | ||
496 | memset (&state, '\0', sizeof (mbstate_t)); | |
497 | if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) | |
498 | { | |
499 | input[3] = '\0'; | |
500 | if (mbrtowc (&wc, input + 4, 4, &state) != 1) | |
501 | result |= 8; | |
502 | } | |
503 | found_some_locale = 1; | |
504 | } | |
505 | if (setlocale (LC_ALL, "Chinese_China.936") != NULL) | |
506 | { | |
507 | char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */ | |
508 | mbstate_t state; | |
509 | wchar_t wc; | |
510 | ||
511 | memset (&state, '\0', sizeof (mbstate_t)); | |
512 | if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) | |
513 | { | |
514 | input[3] = '\0'; | |
515 | if (mbrtowc (&wc, input + 4, 4, &state) != 1) | |
516 | result |= 16; | |
517 | } | |
518 | found_some_locale = 1; | |
519 | } | |
520 | return (found_some_locale ? result : 77); | |
521 | }]])], | |
522 | [gl_cv_func_mbrtowc_retval=yes], | |
523 | [if test $? != 77; then | |
524 | gl_cv_func_mbrtowc_retval=no | |
525 | fi | |
526 | ], | |
527 | [:]) | |
528 | fi | |
529 | ]) | |
530 | ]) | |
531 | ||
532 | dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0. | |
533 | dnl Result is gl_cv_func_mbrtowc_nul_retval. | |
534 | ||
535 | AC_DEFUN([gl_MBRTOWC_NUL_RETVAL], | |
536 | [ | |
537 | AC_REQUIRE([AC_PROG_CC]) | |
538 | AC_REQUIRE([gt_LOCALE_ZH_CN]) | |
539 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
540 | AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character], | |
541 | [gl_cv_func_mbrtowc_nul_retval], | |
542 | [ | |
543 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
544 | dnl is present. | |
545 | changequote(,)dnl | |
546 | case "$host_os" in | |
547 | # Guess no on Solaris 8 and 9. | |
548 | solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;; | |
549 | # Guess yes otherwise. | |
550 | *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;; | |
551 | esac | |
552 | changequote([,])dnl | |
553 | if test $LOCALE_ZH_CN != none; then | |
554 | AC_RUN_IFELSE( | |
555 | [AC_LANG_SOURCE([[ | |
556 | #include <locale.h> | |
557 | #include <string.h> | |
558 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | |
559 | <wchar.h>. | |
560 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
561 | included before <wchar.h>. */ | |
562 | #include <stddef.h> | |
563 | #include <stdio.h> | |
564 | #include <time.h> | |
565 | #include <wchar.h> | |
566 | int main () | |
567 | { | |
568 | /* This fails on Solaris 8 and 9. */ | |
569 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) | |
570 | { | |
571 | mbstate_t state; | |
572 | wchar_t wc; | |
573 | ||
574 | memset (&state, '\0', sizeof (mbstate_t)); | |
575 | if (mbrtowc (&wc, "", 1, &state) != 0) | |
c0c3707f | 576 | return 2; |
8690e634 JK |
577 | } |
578 | return 0; | |
579 | }]])], | |
580 | [gl_cv_func_mbrtowc_nul_retval=yes], | |
581 | [gl_cv_func_mbrtowc_nul_retval=no], | |
582 | [:]) | |
583 | fi | |
584 | ]) | |
585 | ]) | |
586 | ||
4a626d0a PA |
587 | dnl Test whether mbrtowc returns the correct value on empty input. |
588 | ||
589 | AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT], | |
590 | [ | |
591 | AC_REQUIRE([AC_PROG_CC]) | |
592 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
593 | AC_CACHE_CHECK([whether mbrtowc works on empty input], | |
594 | [gl_cv_func_mbrtowc_empty_input], | |
595 | [ | |
596 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
597 | dnl is present. | |
598 | changequote(,)dnl | |
599 | case "$host_os" in | |
c0c3707f CB |
600 | # Guess no on AIX and glibc systems. |
601 | aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; | |
602 | # Guess yes on native Windows. | |
603 | mingw*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; | |
604 | *) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; | |
4a626d0a PA |
605 | esac |
606 | changequote([,])dnl | |
607 | AC_RUN_IFELSE( | |
608 | [AC_LANG_SOURCE([[ | |
609 | #include <wchar.h> | |
610 | static wchar_t wc; | |
611 | static mbstate_t mbs; | |
612 | int | |
613 | main (void) | |
614 | { | |
49e4877c | 615 | return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2; |
4a626d0a | 616 | }]])], |
4a626d0a | 617 | [gl_cv_func_mbrtowc_empty_input=yes], |
49e4877c | 618 | [gl_cv_func_mbrtowc_empty_input=no], |
4a626d0a PA |
619 | [:]) |
620 | ]) | |
621 | ]) | |
622 | ||
49e4877c PA |
623 | dnl Test whether mbrtowc reports encoding errors in the C locale. |
624 | dnl Although POSIX was never intended to allow this, the GNU C Library | |
625 | dnl and other implementations do it. See: | |
626 | dnl https://sourceware.org/bugzilla/show_bug.cgi?id=19932 | |
627 | ||
628 | AC_DEFUN([gl_MBRTOWC_C_LOCALE], | |
629 | [ | |
c0c3707f | 630 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
49e4877c PA |
631 | AC_CACHE_CHECK([whether the C locale is free of encoding errors], |
632 | [gl_cv_C_locale_sans_EILSEQ], | |
633 | [ | |
634 | dnl Initial guess, used when cross-compiling or when no suitable locale | |
635 | dnl is present. | |
c0c3707f | 636 | gl_cv_C_locale_sans_EILSEQ="$gl_cross_guess_normal" |
49e4877c PA |
637 | |
638 | AC_RUN_IFELSE( | |
639 | [AC_LANG_PROGRAM( | |
640 | [[#include <limits.h> | |
641 | #include <locale.h> | |
642 | #include <wchar.h> | |
643 | ]], [[ | |
644 | int i; | |
645 | char *locale = setlocale (LC_ALL, "C"); | |
646 | if (! locale) | |
c0c3707f | 647 | return 2; |
49e4877c PA |
648 | for (i = CHAR_MIN; i <= CHAR_MAX; i++) |
649 | { | |
650 | char c = i; | |
651 | wchar_t wc; | |
652 | mbstate_t mbs = { 0, }; | |
653 | size_t ss = mbrtowc (&wc, &c, 1, &mbs); | |
654 | if (1 < ss) | |
c0c3707f | 655 | return 3; |
49e4877c PA |
656 | } |
657 | return 0; | |
658 | ]])], | |
659 | [gl_cv_C_locale_sans_EILSEQ=yes], | |
660 | [gl_cv_C_locale_sans_EILSEQ=no], | |
c0c3707f CB |
661 | [case "$host_os" in |
662 | # Guess yes on native Windows. | |
663 | mingw*) gl_cv_C_locale_sans_EILSEQ="guessing yes" ;; | |
664 | esac | |
665 | ]) | |
666 | ]) | |
49e4877c PA |
667 | ]) |
668 | ||
8690e634 JK |
669 | # Prerequisites of lib/mbrtowc.c. |
670 | AC_DEFUN([gl_PREREQ_MBRTOWC], [ | |
c0c3707f | 671 | AC_REQUIRE([AC_C_INLINE]) |
8690e634 JK |
672 | : |
673 | ]) | |
674 | ||
675 | ||
676 | dnl From Paul Eggert | |
677 | ||
678 | dnl This is an override of an autoconf macro. | |
679 | ||
680 | AC_DEFUN([AC_FUNC_MBRTOWC], | |
681 | [ | |
682 | dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. | |
683 | AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], | |
c0c3707f | 684 | [gl_cv_func_mbrtowc], |
8690e634 JK |
685 | [AC_LINK_IFELSE( |
686 | [AC_LANG_PROGRAM( | |
687 | [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be | |
688 | included before <wchar.h>. | |
689 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> | |
690 | must be included before <wchar.h>. */ | |
691 | #include <stddef.h> | |
692 | #include <stdio.h> | |
693 | #include <time.h> | |
694 | #include <wchar.h>]], | |
695 | [[wchar_t wc; | |
696 | char const s[] = ""; | |
697 | size_t n = 1; | |
698 | mbstate_t state; | |
699 | return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], | |
c0c3707f CB |
700 | [gl_cv_func_mbrtowc=yes], |
701 | [gl_cv_func_mbrtowc=no])]) | |
8690e634 JK |
702 | if test $gl_cv_func_mbrtowc = yes; then |
703 | AC_DEFINE([HAVE_MBRTOWC], [1], | |
704 | [Define to 1 if mbrtowc and mbstate_t are properly declared.]) | |
705 | fi | |
706 | ]) |