1 # mbsrtowcs.m4 serial 13
2 dnl Copyright (C) 2008-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_MBSRTOWCS],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 AC_CHECK_FUNCS_ONCE([mbsrtowcs])
15 if test $ac_cv_func_mbsrtowcs = no; then
17 AC_CHECK_DECLS([mbsrtowcs],,, [[
18 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
20 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
21 included before <wchar.h>. */
27 if test $ac_cv_have_decl_mbsrtowcs = yes; then
28 dnl On Minix 3.1.8, the system's <wchar.h> declares mbsrtowcs() although
29 dnl it does not have the function. Avoid a collision with gnulib's
34 if test $REPLACE_MBSTATE_T = 1; then
38 case "$gl_cv_func_mbsrtowcs_works" in
40 *) REPLACE_MBSRTOWCS=1 ;;
46 dnl Test whether mbsrtowcs works.
47 dnl Result is gl_cv_func_mbsrtowcs_works.
49 AC_DEFUN([gl_MBSRTOWCS_WORKS],
51 AC_REQUIRE([AC_PROG_CC])
52 AC_REQUIRE([gt_LOCALE_FR])
53 AC_REQUIRE([gt_LOCALE_FR_UTF8])
54 AC_REQUIRE([gt_LOCALE_JA])
55 AC_REQUIRE([gt_LOCALE_ZH_CN])
56 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
57 AC_CACHE_CHECK([whether mbsrtowcs works],
58 [gl_cv_func_mbsrtowcs_works],
60 dnl Initial guess, used when cross-compiling or when no suitable locale
64 # Guess no on HP-UX, Solaris, mingw.
65 hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
66 # Guess yes otherwise.
67 *) gl_cv_func_mbsrtowcs_works="guessing yes" ;;
70 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
75 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
77 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
78 included before <wchar.h>. */
86 /* Test whether the function supports a NULL destination argument.
87 This fails on native Windows. */
88 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
90 const char input[] = "\337er";
91 const char *src = input;
94 memset (&state, '\0', sizeof (mbstate_t));
95 if (mbsrtowcs (NULL, &src, 1, &state) != 3
99 /* Test whether the function works when started with a conversion state
100 in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
101 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
103 const char input[] = "B\303\274\303\237er";
106 memset (&state, '\0', sizeof (mbstate_t));
107 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
108 if (!mbsinit (&state))
110 const char *src = input + 2;
111 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
115 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
117 const char input[] = "<\306\374\313\334\270\354>";
120 memset (&state, '\0', sizeof (mbstate_t));
121 if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
122 if (!mbsinit (&state))
124 const char *src = input + 4;
125 if (mbsrtowcs (NULL, &src, 10, &state) != 3)
129 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
131 const char input[] = "B\250\271\201\060\211\070er";
134 memset (&state, '\0', sizeof (mbstate_t));
135 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
136 if (!mbsinit (&state))
138 const char *src = input + 2;
139 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
145 [gl_cv_func_mbsrtowcs_works=yes],
146 [gl_cv_func_mbsrtowcs_works=no],
152 # Prerequisites of lib/mbsrtowcs.c.
153 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [