1 # mbsnrtowcs.m4 serial 6
2 dnl Copyright (C) 2008, 2010-2021 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_MBSNRTOWCS],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 dnl Persuade glibc <wchar.h> to declare mbsnrtowcs().
12 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14 AC_REQUIRE([AC_TYPE_MBSTATE_T])
17 AC_CHECK_FUNCS_ONCE([mbsnrtowcs])
18 if test $ac_cv_func_mbsnrtowcs = no; then
21 if test $REPLACE_MBSTATE_T = 1; then
24 gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE
25 case "$gl_cv_func_mbsnrtowcs_works_in_traditional_locale" in
27 *) REPLACE_MBSNRTOWCS=1 ;;
33 # Prerequisites of lib/mbsnrtowcs.c.
34 AC_DEFUN([gl_PREREQ_MBSNRTOWCS], [
38 dnl Test whether mbsnrtowcs works in an ISO-8859-1 locale.
39 dnl Result is gl_cv_func_mbsnrtowcs_works_in_traditional_locale.
41 AC_DEFUN([gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE],
43 AC_REQUIRE([AC_PROG_CC])
44 AC_REQUIRE([gt_LOCALE_FR])
45 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
46 AC_CACHE_CHECK([whether mbsnrtowcs works in a traditional locale],
47 [gl_cv_func_mbsnrtowcs_works_in_traditional_locale],
49 dnl Initial guess, used when cross-compiling or when no suitable locale
53 # Guess no on Solaris.
54 solaris*) gl_cv_func_mbsnrtowcs_works_in_traditional_locale="guessing no" ;;
55 # Guess yes otherwise.
56 *) gl_cv_func_mbsnrtowcs_works_in_traditional_locale="guessing yes" ;;
59 if test $LOCALE_FR != none; then
68 /* This fails on Solaris 11.4:
69 mbsnrtowcs stores a wrong wide character: 0xDF instead of btowc (0xDF). */
70 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
72 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
73 char input[] = "B\374\337er"; /* "Büßer" */
84 for (i = 0; i < BUFSIZE; i++)
85 buf[i] = (wchar_t) 0xBADFACE;
88 memset (&state, '\0', sizeof (mbstate_t));
90 wc = (wchar_t) 0xBADFACE;
91 ret = mbrtowc (&wc, input, 1, &state);
92 if (!(ret == 1 && wc == 'B' && mbsinit (&state)))
96 wc = (wchar_t) 0xBADFACE;
97 ret = mbrtowc (&wc, input + 1, 1, &state);
98 if (!(ret == 1 && wctob (wc) == (unsigned char) '\374' && mbsinit (&state)))
104 ret = mbsnrtowcs (NULL, &src, 4, 1, &temp_state);
105 if (!(ret == 3 && src == input + 2 && mbsinit (&state)))
109 ret = mbsnrtowcs (buf, &src, 4, 1, &state);
112 if (!(src == input + 3))
114 if (!(buf[0] == btowc ((unsigned char) '\337')))
119 [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=yes],
120 [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=no],