maint: update almost all copyright ranges to include 2011
[gnulib.git] / m4 / mbsrtowcs.m4
1 # mbsrtowcs.m4 serial 9
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.
6
7 AC_DEFUN([gl_FUNC_MBSRTOWCS],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11   AC_REQUIRE([AC_TYPE_MBSTATE_T])
12   gl_MBSTATE_T_BROKEN
13
14   AC_CHECK_FUNCS_ONCE([mbsrtowcs])
15   if test $ac_cv_func_mbsrtowcs = no; then
16     HAVE_MBSRTOWCS=0
17   else
18     if test $REPLACE_MBSTATE_T = 1; then
19       REPLACE_MBSRTOWCS=1
20     else
21       gl_MBSRTOWCS_WORKS
22       case "$gl_cv_func_mbsrtowcs_works" in
23         *yes) ;;
24         *) REPLACE_MBSRTOWCS=1 ;;
25       esac
26     fi
27   fi
28   if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then
29     gl_REPLACE_WCHAR_H
30     AC_LIBOBJ([mbsrtowcs])
31     AC_LIBOBJ([mbsrtowcs-state])
32     gl_PREREQ_MBSRTOWCS
33   fi
34 ])
35
36 dnl Test whether mbsrtowcs works.
37 dnl Result is gl_cv_func_mbsrtowcs_works.
38
39 AC_DEFUN([gl_MBSRTOWCS_WORKS],
40 [
41   AC_REQUIRE([AC_PROG_CC])
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],
48     [
49       dnl Initial guess, used when cross-compiling or when no suitable locale
50       dnl is present.
51 changequote(,)dnl
52       case "$host_os" in
53                           # Guess no on HP-UX and Solaris.
54         hpux* | solaris*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
55                           # Guess yes otherwise.
56         *)                gl_cv_func_mbsrtowcs_works="guessing yes" ;;
57       esac
58 changequote([,])dnl
59       if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
60         AC_RUN_IFELSE(
61           [AC_LANG_SOURCE([[
62 #include <locale.h>
63 #include <string.h>
64 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
65    <wchar.h>.
66    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
67    included before <wchar.h>.  */
68 #include <stddef.h>
69 #include <stdio.h>
70 #include <time.h>
71 #include <wchar.h>
72 int main ()
73 {
74   int result = 0;
75   /* Test whether the function works when started with a conversion state
76      in non-initial state.  This fails on HP-UX 11.11 and Solaris 10.  */
77   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
78     {
79       const char input[] = "B\303\274\303\237er";
80       mbstate_t state;
81
82       memset (&state, '\0', sizeof (mbstate_t));
83       if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
84         if (!mbsinit (&state))
85           {
86             const char *src = input + 2;
87             if (mbsrtowcs (NULL, &src, 10, &state) != 4)
88               result |= 1;
89           }
90     }
91   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
92     {
93       const char input[] = "<\306\374\313\334\270\354>";
94       mbstate_t state;
95
96       memset (&state, '\0', sizeof (mbstate_t));
97       if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
98         if (!mbsinit (&state))
99           {
100             const char *src = input + 4;
101             if (mbsrtowcs (NULL, &src, 10, &state) != 3)
102               result |= 2;
103           }
104     }
105   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
106     {
107       const char input[] = "B\250\271\201\060\211\070er";
108       mbstate_t state;
109
110       memset (&state, '\0', sizeof (mbstate_t));
111       if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
112         if (!mbsinit (&state))
113           {
114             const char *src = input + 2;
115             if (mbsrtowcs (NULL, &src, 10, &state) != 4)
116               result |= 4;
117           }
118     }
119   return result;
120 }]])],
121           [gl_cv_func_mbsrtowcs_works=yes],
122           [gl_cv_func_mbsrtowcs_works=no],
123           [:])
124       fi
125     ])
126 ])
127
128 # Prerequisites of lib/mbsrtowcs.c.
129 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
130   :
131 ])