Debian Codegraph @

m4/mbsrtowcs.m4

raw
1 # mbsrtowcs.m4
2 # serial 19
3 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FUNC_MBSRTOWCS],
10 [
11 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12
13 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 gl_MBSTATE_T_BROKEN
15
16 AC_CHECK_FUNCS_ONCE([mbsrtowcs])
17 if test $ac_cv_func_mbsrtowcs = no; then
18 HAVE_MBSRTOWCS=0
19 AC_CHECK_DECLS([mbsrtowcs],,, [[
20 #include <wchar.h>
21 ]])
22 if test $ac_cv_have_decl_mbsrtowcs = yes; then
23 dnl On Minix 3.1.8, the system's <wchar.h> declares mbsrtowcs() although
24 dnl it does not have the function. Avoid a collision with gnulib's
25 dnl replacement.
26 REPLACE_MBSRTOWCS=1
27 fi
28 else
29 if test $REPLACE_MBSTATE_T = 1; then
30 REPLACE_MBSRTOWCS=1
31 else
32 gl_MBSRTOWCS_WORKS
33 case "$gl_cv_func_mbsrtowcs_works" in
34 *yes) ;;
35 *) REPLACE_MBSRTOWCS=1 ;;
36 esac
37 if test $REPLACE_MBSRTOWCS = 0; then
38 gl_MBRTOWC_C_LOCALE
39 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
40 *yes) ;;
41 *) REPLACE_MBSRTOWCS=1 ;;
42 esac
43 fi
44 fi
45 fi
46 ])
47
48 dnl Test whether mbsrtowcs works.
49 dnl Result is gl_cv_func_mbsrtowcs_works.
50
51 AC_DEFUN([gl_MBSRTOWCS_WORKS],
52 [
53 AC_REQUIRE([AC_PROG_CC])
54 AC_REQUIRE([gt_LOCALE_FR])
55 AC_REQUIRE([gt_LOCALE_EN_UTF8])
56 AC_REQUIRE([gt_LOCALE_JA])
57 AC_REQUIRE([gt_LOCALE_ZH_CN])
58 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
59 AC_CACHE_CHECK([whether mbsrtowcs works],
60 [gl_cv_func_mbsrtowcs_works],
61 [
62 dnl Initial guess, used when cross-compiling or when no suitable locale
63 dnl is present.
64 changequote(,)dnl
65 case "$host_os" in
66 # Guess no on HP-UX, Solaris, mingw.
67 hpux* | solaris* | mingw* | windows*)
68 gl_cv_func_mbsrtowcs_works="guessing no" ;;
69 # Guess yes otherwise.
70 *)
71 gl_cv_func_mbsrtowcs_works="guessing yes" ;;
72 esac
73 changequote([,])dnl
74 if test $LOCALE_FR != none || test "$LOCALE_EN_UTF8" != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
75 AC_RUN_IFELSE(
76 [AC_LANG_SOURCE([[
77 #include <locale.h>
78 #include <string.h>
79 #include <wchar.h>
80 int main ()
81 {
82 int result = 0;
83 /* Test whether the function supports a NULL destination argument.
84 This fails on native Windows. */
85 if (strcmp ("$LOCALE_FR", "none") != 0
86 && setlocale (LC_ALL, "$LOCALE_FR") != NULL)
87 {
88 const char input[] = "\337er";
89 const char *src = input;
90 mbstate_t state;
91
92 memset (&state, '\0', sizeof (mbstate_t));
93 if (mbsrtowcs (NULL, &src, 1, &state) != 3
94 || src != input)
95 result |= 1;
96 }
97 /* Test whether the function works when started with a conversion state
98 in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
99 if (strcmp ("$LOCALE_EN_UTF8", "none") != 0
100 && setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
101 {
102 const char input[] = "B\303\274\303\237er";
103 mbstate_t state;
104
105 memset (&state, '\0', sizeof (mbstate_t));
106 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
107 if (!mbsinit (&state))
108 {
109 const char *src = input + 2;
110 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
111 result |= 2;
112 }
113 }
114 if (strcmp ("$LOCALE_JA", "none") != 0
115 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
116 {
117 const char input[] = "<\306\374\313\334\270\354>";
118 mbstate_t state;
119
120 memset (&state, '\0', sizeof (mbstate_t));
121 if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
122 if (!mbsinit (&state))
123 {
124 const char *src = input + 4;
125 if (mbsrtowcs (NULL, &src, 10, &state) != 3)
126 result |= 4;
127 }
128 }
129 if (strcmp ("$LOCALE_ZH_CN", "none") != 0
130 && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
131 {
132 const char input[] = "B\250\271\201\060\211\070er";
133 mbstate_t state;
134
135 memset (&state, '\0', sizeof (mbstate_t));
136 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
137 if (!mbsinit (&state))
138 {
139 const char *src = input + 2;
140 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
141 result |= 8;
142 }
143 }
144 return result;
145 }]])],
146 [gl_cv_func_mbsrtowcs_works=yes],
147 [gl_cv_func_mbsrtowcs_works=no],
148 [:])
149 fi
150 ])
151 ])
152
153 # Prerequisites of lib/mbsrtowcs.c.
154 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
155 :
156 ])