1 # mbsrtowcs.m4 serial 11
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
29 AC_LIBOBJ([mbsrtowcs])
30 AC_LIBOBJ([mbsrtowcs-state])
35 dnl Test whether mbsrtowcs works.
36 dnl Result is gl_cv_func_mbsrtowcs_works.
38 AC_DEFUN([gl_MBSRTOWCS_WORKS],
40 AC_REQUIRE([AC_PROG_CC])
41 AC_REQUIRE([gt_LOCALE_FR])
42 AC_REQUIRE([gt_LOCALE_FR_UTF8])
43 AC_REQUIRE([gt_LOCALE_JA])
44 AC_REQUIRE([gt_LOCALE_ZH_CN])
45 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
46 AC_CACHE_CHECK([whether mbsrtowcs works],
47 [gl_cv_func_mbsrtowcs_works],
49 dnl Initial guess, used when cross-compiling or when no suitable locale
53 # Guess no on HP-UX, Solaris, mingw.
54 hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
55 # Guess yes otherwise.
56 *) gl_cv_func_mbsrtowcs_works="guessing yes" ;;
59 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
64 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
66 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
67 included before <wchar.h>. */
75 /* Test whether the function supports a NULL destination argument.
76 This fails on native Windows. */
77 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
79 const char input[] = "\337er";
80 const char *src = input;
83 memset (&state, '\0', sizeof (mbstate_t));
84 if (mbsrtowcs (NULL, &src, 1, &state) != 3
88 /* Test whether the function works when started with a conversion state
89 in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
90 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
92 const char input[] = "B\303\274\303\237er";
95 memset (&state, '\0', sizeof (mbstate_t));
96 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
97 if (!mbsinit (&state))
99 const char *src = input + 2;
100 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
104 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
106 const char input[] = "<\306\374\313\334\270\354>";
109 memset (&state, '\0', sizeof (mbstate_t));
110 if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
111 if (!mbsinit (&state))
113 const char *src = input + 4;
114 if (mbsrtowcs (NULL, &src, 10, &state) != 3)
118 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
120 const char input[] = "B\250\271\201\060\211\070er";
123 memset (&state, '\0', sizeof (mbstate_t));
124 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
125 if (!mbsinit (&state))
127 const char *src = input + 2;
128 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
134 [gl_cv_func_mbsrtowcs_works=yes],
135 [gl_cv_func_mbsrtowcs_works=no],
141 # Prerequisites of lib/mbsrtowcs.c.
142 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [