Debian Codegraph @

m4/mbrtowc.m4

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