Debian Codegraph @

m4/mbsrtowcs.m4

raw
1 # mbsrtowcs.m4 serial 16
2 dnl Copyright (C) 2008-2023 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 AC_CHECK_DECLS([mbsrtowcs],,, [[
18 #include <wchar.h>
19 ]])
20 if test $ac_cv_have_decl_mbsrtowcs = yes; then
21 dnl On Minix 3.1.8, the system's <wchar.h> declares mbsrtowcs() although
22 dnl it does not have the function. Avoid a collision with gnulib's
23 dnl replacement.
24 REPLACE_MBSRTOWCS=1
25 fi
26 else
27 if test $REPLACE_MBSTATE_T = 1; then
28 REPLACE_MBSRTOWCS=1
29 else
30 gl_MBSRTOWCS_WORKS
31 case "$gl_cv_func_mbsrtowcs_works" in
32 *yes) ;;
33 *) REPLACE_MBSRTOWCS=1 ;;
34 esac
35 if test $REPLACE_MBSRTOWCS = 0; then
36 gl_MBRTOWC_C_LOCALE
37 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
38 *yes) ;;
39 *) REPLACE_MBSRTOWCS=1 ;;
40 esac
41 fi
42 fi
43 fi
44 ])
45
46 dnl Test whether mbsrtowcs works.
47 dnl Result is gl_cv_func_mbsrtowcs_works.
48
49 AC_DEFUN([gl_MBSRTOWCS_WORKS],
50 [
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],
59 [
60 dnl Initial guess, used when cross-compiling or when no suitable locale
61 dnl is present.
62 changequote(,)dnl
63 case "$host_os" in
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" ;;
68 esac
69 changequote([,])dnl
70 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
71 AC_RUN_IFELSE(
72 [AC_LANG_SOURCE([[
73 #include <locale.h>
74 #include <string.h>
75 #include <wchar.h>
76 int main ()
77 {
78 int result = 0;
79 /* Test whether the function supports a NULL destination argument.
80 This fails on native Windows. */
81 if (strcmp ("$LOCALE_FR", "none") != 0
82 && setlocale (LC_ALL, "$LOCALE_FR") != NULL)
83 {
84 const char input[] = "\337er";
85 const char *src = input;
86 mbstate_t state;
87
88 memset (&state, '\0', sizeof (mbstate_t));
89 if (mbsrtowcs (NULL, &src, 1, &state) != 3
90 || src != input)
91 result |= 1;
92 }
93 /* Test whether the function works when started with a conversion state
94 in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
95 if (strcmp ("$LOCALE_FR_UTF8", "none") != 0
96 && setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
97 {
98 const char input[] = "B\303\274\303\237er";
99 mbstate_t state;
100
101 memset (&state, '\0', sizeof (mbstate_t));
102 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
103 if (!mbsinit (&state))
104 {
105 const char *src = input + 2;
106 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
107 result |= 2;
108 }
109 }
110 if (strcmp ("$LOCALE_JA", "none") != 0
111 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
112 {
113 const char input[] = "<\306\374\313\334\270\354>";
114 mbstate_t state;
115
116 memset (&state, '\0', sizeof (mbstate_t));
117 if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
118 if (!mbsinit (&state))
119 {
120 const char *src = input + 4;
121 if (mbsrtowcs (NULL, &src, 10, &state) != 3)
122 result |= 4;
123 }
124 }
125 if (strcmp ("$LOCALE_ZH_CN", "none") != 0
126 && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
127 {
128 const char input[] = "B\250\271\201\060\211\070er";
129 mbstate_t state;
130
131 memset (&state, '\0', sizeof (mbstate_t));
132 if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
133 if (!mbsinit (&state))
134 {
135 const char *src = input + 2;
136 if (mbsrtowcs (NULL, &src, 10, &state) != 4)
137 result |= 8;
138 }
139 }
140 return result;
141 }]])],
142 [gl_cv_func_mbsrtowcs_works=yes],
143 [gl_cv_func_mbsrtowcs_works=no],
144 [:])
145 fi
146 ])
147 ])
148
149 # Prerequisites of lib/mbsrtowcs.c.
150 AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
151 :
152 ])