1 # mbsrtowcs.m4 serial 10
2 dnl Copyright (C) 2008-2011 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
18 if test $REPLACE_MBSTATE_T = 1; then
22 case "$gl_cv_func_mbsrtowcs_works" in
24 *) REPLACE_MBSRTOWCS=1 ;;
28 if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then
30 AC_LIBOBJ([mbsrtowcs])
31 AC_LIBOBJ([mbsrtowcs-state])
36 dnl Test whether mbsrtowcs works.
37 dnl Result is gl_cv_func_mbsrtowcs_works.
39 AC_DEFUN([gl_MBSRTOWCS_WORKS],
41 AC_REQUIRE([AC_PROG_CC])
42 AC_REQUIRE([gt_LOCALE_FR])
43 AC_REQUIRE([gt_LOCALE_FR_UTF8])
44 AC_REQUIRE([gt_LOCALE_JA])
45 AC_REQUIRE([gt_LOCALE_ZH_CN])
46 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
47 AC_CACHE_CHECK([whether mbsrtowcs works],
48 [gl_cv_func_mbsrtowcs_works],
50 dnl Initial guess, used when cross-compiling or when no suitable locale
54 # Guess no on HP-UX, Solaris, mingw.
55 hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
56 # Guess yes otherwise.
57 *) gl_cv_func_mbsrtowcs_works="guessing yes" ;;
60 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != 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>. */
76 /* Test whether the function supports a NULL destination argument.
77 This fails on native Windows. */
78 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
80 const char input[] = "\337er";
81 const char *src = input;
84 memset (&state, '\0', sizeof (mbstate_t));
85 if (mbsrtowcs (NULL, &src, 1, &state) != 3
89 /* Test whether the function works when started with a conversion state
90 in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
91 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
93 const char input[] = "B\303\274\303\237er";
96 memset (&state, '\0', sizeof (mbstate_t));
97 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
98 if (!mbsinit (&state))
100 const char *src = input + 2;
101 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
105 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
107 const char input[] = "<\306\374\313\334\270\354>";
110 memset (&state, '\0', sizeof (mbstate_t));
111 if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
112 if (!mbsinit (&state))
114 const char *src = input + 4;
115 if (mbsrtowcs (NULL, &src, 10, &state) != 3)
119 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
121 const char input[] = "B\250\271\201\060\211\070er";
124 memset (&state, '\0', sizeof (mbstate_t));
125 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
126 if (!mbsinit (&state))
128 const char *src = input + 2;
129 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
135 [gl_cv_func_mbsrtowcs_works=yes],
136 [gl_cv_func_mbsrtowcs_works=no],
142 # Prerequisites of lib/mbsrtowcs.c.
143 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [