1 # mbsnrtowcs.m4 serial 5
2 dnl Copyright (C) 2008, 2010-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.
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
65 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
67 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
68 included before <wchar.h>. */
75 /* This fails on Solaris 11.4:
76 mbsnrtowcs stores a wrong wide character: 0xDF instead of btowc (0xDF). */
77 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
79 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
80 char input[] = "B\374\337er"; /* "Büßer" */
91 for (i = 0; i < BUFSIZE; i++)
92 buf[i] = (wchar_t) 0xBADFACE;
95 memset (&state, '\0', sizeof (mbstate_t));
97 wc = (wchar_t) 0xBADFACE;
98 ret = mbrtowc (&wc, input, 1, &state);
99 if (!(ret == 1 && wc == 'B' && mbsinit (&state)))
103 wc = (wchar_t) 0xBADFACE;
104 ret = mbrtowc (&wc, input + 1, 1, &state);
105 if (!(ret == 1 && wctob (wc) == (unsigned char) '\374' && mbsinit (&state)))
111 ret = mbsnrtowcs (NULL, &src, 4, 1, &temp_state);
112 if (!(ret == 3 && src == input + 2 && mbsinit (&state)))
116 ret = mbsnrtowcs (buf, &src, 4, 1, &state);
119 if (!(src == input + 3))
121 if (!(buf[0] == btowc ((unsigned char) '\337')))
126 [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=yes],
127 [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=no],