diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-15 09:22:57 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-15 10:19:08 (GMT) |
commit | 71cdb52799220f8d9052643baf1d3e9836a9c755 (patch) | |
tree | 27aee97a35d9ab51f0d8f64a46690bd41a5f8c1b /gl/m4/mbrtowc.m4 | |
parent | f7afa46586645e50498d8b2d0c67884f014dc3a4 (diff) | |
download | monitoring-plugins-71cdb52799220f8d9052643baf1d3e9836a9c755.tar.gz |
Sync with gnulib
Diffstat (limited to 'gl/m4/mbrtowc.m4')
-rw-r--r-- | gl/m4/mbrtowc.m4 | 325 |
1 files changed, 325 insertions, 0 deletions
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4 new file mode 100644 index 0000000..726497b --- /dev/null +++ b/gl/m4/mbrtowc.m4 | |||
@@ -0,0 +1,325 @@ | |||
1 | # mbrtowc.m4 serial 13 | ||
2 | dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 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_MBRTOWC], | ||
8 | [ | ||
9 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) | ||
10 | |||
11 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) | ||
12 | gl_MBSTATE_T_BROKEN | ||
13 | if test $REPLACE_MBSTATE_T = 1; then | ||
14 | REPLACE_MBRTOWC=1 | ||
15 | fi | ||
16 | AC_CHECK_FUNCS_ONCE([mbrtowc]) | ||
17 | if test $ac_cv_func_mbrtowc = no; then | ||
18 | HAVE_MBRTOWC=0 | ||
19 | fi | ||
20 | if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then | ||
21 | gl_MBRTOWC_NULL_ARG | ||
22 | gl_MBRTOWC_RETVAL | ||
23 | gl_MBRTOWC_NUL_RETVAL | ||
24 | case "$gl_cv_func_mbrtowc_null_arg" in | ||
25 | *yes) ;; | ||
26 | *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1], | ||
27 | [Define if the mbrtowc function has the NULL string argument bug.]) | ||
28 | REPLACE_MBRTOWC=1 | ||
29 | ;; | ||
30 | esac | ||
31 | case "$gl_cv_func_mbrtowc_retval" in | ||
32 | *yes) ;; | ||
33 | *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], | ||
34 | [Define if the mbrtowc function returns a wrong return value.]) | ||
35 | REPLACE_MBRTOWC=1 | ||
36 | ;; | ||
37 | esac | ||
38 | case "$gl_cv_func_mbrtowc_nul_retval" in | ||
39 | *yes) ;; | ||
40 | *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1], | ||
41 | [Define if the mbrtowc function does not return 0 for a NUL character.]) | ||
42 | REPLACE_MBRTOWC=1 | ||
43 | ;; | ||
44 | esac | ||
45 | fi | ||
46 | if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then | ||
47 | gl_REPLACE_WCHAR_H | ||
48 | AC_LIBOBJ([mbrtowc]) | ||
49 | gl_PREREQ_MBRTOWC | ||
50 | fi | ||
51 | ]) | ||
52 | |||
53 | dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that | ||
54 | dnl redefines the semantics of the given mbstate_t type. | ||
55 | dnl Result is REPLACE_MBSTATE_T. | ||
56 | dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to | ||
57 | dnl avoid inconsistencies. | ||
58 | |||
59 | AC_DEFUN([gl_MBSTATE_T_BROKEN], | ||
60 | [ | ||
61 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) | ||
62 | |||
63 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) | ||
64 | AC_CHECK_FUNCS_ONCE([mbsinit]) | ||
65 | AC_CHECK_FUNCS_ONCE([mbrtowc]) | ||
66 | if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then | ||
67 | gl_MBRTOWC_INCOMPLETE_STATE | ||
68 | case "$gl_cv_func_mbrtowc_incomplete_state" in | ||
69 | *yes) REPLACE_MBSTATE_T=0 ;; | ||
70 | *) REPLACE_MBSTATE_T=1 ;; | ||
71 | esac | ||
72 | else | ||
73 | REPLACE_MBSTATE_T=1 | ||
74 | fi | ||
75 | if test $REPLACE_MBSTATE_T = 1; then | ||
76 | gl_REPLACE_WCHAR_H | ||
77 | fi | ||
78 | ]) | ||
79 | |||
80 | dnl Test whether mbrtowc puts the state into non-initial state when parsing an | ||
81 | dnl incomplete multibyte character. | ||
82 | dnl Result is gl_cv_func_mbrtowc_incomplete_state. | ||
83 | |||
84 | AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE], | ||
85 | [ | ||
86 | AC_REQUIRE([AC_PROG_CC]) | ||
87 | AC_REQUIRE([gt_LOCALE_JA]) | ||
88 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
89 | AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], | ||
90 | [gl_cv_func_mbrtowc_incomplete_state], | ||
91 | [ | ||
92 | dnl Initial guess, used when cross-compiling or when no suitable locale | ||
93 | dnl is present. | ||
94 | changequote(,)dnl | ||
95 | case "$host_os" in | ||
96 | # Guess no on AIX and OSF/1. | ||
97 | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;; | ||
98 | # Guess yes otherwise. | ||
99 | *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;; | ||
100 | esac | ||
101 | changequote([,])dnl | ||
102 | if test $LOCALE_JA != none; then | ||
103 | AC_TRY_RUN([ | ||
104 | #include <locale.h> | ||
105 | #include <string.h> | ||
106 | #include <wchar.h> | ||
107 | int main () | ||
108 | { | ||
109 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) | ||
110 | { | ||
111 | const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ | ||
112 | mbstate_t state; | ||
113 | wchar_t wc; | ||
114 | |||
115 | memset (&state, '\0', sizeof (mbstate_t)); | ||
116 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | ||
117 | if (mbsinit (&state)) | ||
118 | return 1; | ||
119 | } | ||
120 | return 0; | ||
121 | }], | ||
122 | [gl_cv_func_mbrtowc_incomplete_state=yes], | ||
123 | [gl_cv_func_mbrtowc_incomplete_state=no], | ||
124 | []) | ||
125 | fi | ||
126 | ]) | ||
127 | ]) | ||
128 | |||
129 | dnl Test whether mbrtowc supports a NULL string argument correctly. | ||
130 | dnl Result is gl_cv_func_mbrtowc_null_arg. | ||
131 | |||
132 | AC_DEFUN([gl_MBRTOWC_NULL_ARG], | ||
133 | [ | ||
134 | AC_REQUIRE([AC_PROG_CC]) | ||
135 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) | ||
136 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
137 | AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument], | ||
138 | [gl_cv_func_mbrtowc_null_arg], | ||
139 | [ | ||
140 | dnl Initial guess, used when cross-compiling or when no suitable locale | ||
141 | dnl is present. | ||
142 | changequote(,)dnl | ||
143 | case "$host_os" in | ||
144 | # Guess no on OSF/1. | ||
145 | osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;; | ||
146 | # Guess yes otherwise. | ||
147 | *) gl_cv_func_mbrtowc_null_arg="guessing yes" ;; | ||
148 | esac | ||
149 | changequote([,])dnl | ||
150 | if test $LOCALE_FR_UTF8 != none; then | ||
151 | AC_TRY_RUN([ | ||
152 | #include <locale.h> | ||
153 | #include <string.h> | ||
154 | #include <wchar.h> | ||
155 | int main () | ||
156 | { | ||
157 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | ||
158 | { | ||
159 | mbstate_t state; | ||
160 | wchar_t wc; | ||
161 | int ret; | ||
162 | |||
163 | memset (&state, '\0', sizeof (mbstate_t)); | ||
164 | wc = (wchar_t) 0xBADFACE; | ||
165 | mbrtowc (&wc, NULL, 5, &state); | ||
166 | /* Check that wc was not modified. */ | ||
167 | if (wc != (wchar_t) 0xBADFACE) | ||
168 | return 1; | ||
169 | } | ||
170 | return 0; | ||
171 | }], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], []) | ||
172 | fi | ||
173 | ]) | ||
174 | ]) | ||
175 | |||
176 | dnl Test whether mbrtowc, when parsing the end of a multibyte character, | ||
177 | dnl correctly returns the number of bytes that were needed to complete the | ||
178 | dnl character (not the total number of bytes of the multibyte character). | ||
179 | dnl Result is gl_cv_func_mbrtowc_retval. | ||
180 | |||
181 | AC_DEFUN([gl_MBRTOWC_RETVAL], | ||
182 | [ | ||
183 | AC_REQUIRE([AC_PROG_CC]) | ||
184 | AC_REQUIRE([gt_LOCALE_FR_UTF8]) | ||
185 | AC_REQUIRE([gt_LOCALE_JA]) | ||
186 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
187 | AC_CACHE_CHECK([whether mbrtowc has a correct return value], | ||
188 | [gl_cv_func_mbrtowc_retval], | ||
189 | [ | ||
190 | dnl Initial guess, used when cross-compiling or when no suitable locale | ||
191 | dnl is present. | ||
192 | changequote(,)dnl | ||
193 | case "$host_os" in | ||
194 | # Guess no on HP-UX and Solaris. | ||
195 | hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;; | ||
196 | # Guess yes otherwise. | ||
197 | *) gl_cv_func_mbrtowc_retval="guessing yes" ;; | ||
198 | esac | ||
199 | changequote([,])dnl | ||
200 | if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then | ||
201 | AC_TRY_RUN([ | ||
202 | #include <locale.h> | ||
203 | #include <string.h> | ||
204 | #include <wchar.h> | ||
205 | int main () | ||
206 | { | ||
207 | /* This fails on Solaris. */ | ||
208 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) | ||
209 | { | ||
210 | char input[] = "B\303\274\303\237er"; /* "Büßer" */ | ||
211 | mbstate_t state; | ||
212 | wchar_t wc; | ||
213 | |||
214 | memset (&state, '\0', sizeof (mbstate_t)); | ||
215 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | ||
216 | { | ||
217 | input[1] = '\0'; | ||
218 | if (mbrtowc (&wc, input + 2, 5, &state) != 1) | ||
219 | return 1; | ||
220 | } | ||
221 | } | ||
222 | /* This fails on HP-UX 11.11. */ | ||
223 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) | ||
224 | { | ||
225 | char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ | ||
226 | mbstate_t state; | ||
227 | wchar_t wc; | ||
228 | |||
229 | memset (&state, '\0', sizeof (mbstate_t)); | ||
230 | if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) | ||
231 | { | ||
232 | input[1] = '\0'; | ||
233 | if (mbrtowc (&wc, input + 2, 5, &state) != 2) | ||
234 | return 1; | ||
235 | } | ||
236 | } | ||
237 | return 0; | ||
238 | }], | ||
239 | [gl_cv_func_mbrtowc_retval=yes], | ||
240 | [gl_cv_func_mbrtowc_retval=no], | ||
241 | []) | ||
242 | fi | ||
243 | ]) | ||
244 | ]) | ||
245 | |||
246 | dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0. | ||
247 | dnl Result is gl_cv_func_mbrtowc_nul_retval. | ||
248 | |||
249 | AC_DEFUN([gl_MBRTOWC_NUL_RETVAL], | ||
250 | [ | ||
251 | AC_REQUIRE([AC_PROG_CC]) | ||
252 | AC_REQUIRE([gt_LOCALE_ZH_CN]) | ||
253 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
254 | AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character], | ||
255 | [gl_cv_func_mbrtowc_nul_retval], | ||
256 | [ | ||
257 | dnl Initial guess, used when cross-compiling or when no suitable locale | ||
258 | dnl is present. | ||
259 | changequote(,)dnl | ||
260 | case "$host_os" in | ||
261 | # Guess no on Solaris 9. | ||
262 | solaris2.9) gl_cv_func_mbrtowc_nul_retval="guessing no" ;; | ||
263 | # Guess yes otherwise. | ||
264 | *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;; | ||
265 | esac | ||
266 | changequote([,])dnl | ||
267 | if test $LOCALE_ZH_CN != none; then | ||
268 | AC_TRY_RUN([ | ||
269 | #include <locale.h> | ||
270 | #include <string.h> | ||
271 | #include <wchar.h> | ||
272 | int main () | ||
273 | { | ||
274 | /* This fails on Solaris 9. */ | ||
275 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) | ||
276 | { | ||
277 | mbstate_t state; | ||
278 | wchar_t wc; | ||
279 | |||
280 | memset (&state, '\0', sizeof (mbstate_t)); | ||
281 | if (mbrtowc (&wc, "", 1, &state) != 0) | ||
282 | return 1; | ||
283 | } | ||
284 | return 0; | ||
285 | }], | ||
286 | [gl_cv_func_mbrtowc_nul_retval=yes], | ||
287 | [gl_cv_func_mbrtowc_nul_retval=no], | ||
288 | []) | ||
289 | fi | ||
290 | ]) | ||
291 | ]) | ||
292 | |||
293 | # Prerequisites of lib/mbrtowc.c. | ||
294 | AC_DEFUN([gl_PREREQ_MBRTOWC], [ | ||
295 | : | ||
296 | ]) | ||
297 | |||
298 | |||
299 | dnl From Paul Eggert | ||
300 | |||
301 | dnl This override of an autoconf macro can be removed when autoconf 2.60 or | ||
302 | dnl newer can be assumed everywhere. | ||
303 | |||
304 | m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[ | ||
305 | AC_DEFUN([AC_FUNC_MBRTOWC], | ||
306 | [ | ||
307 | dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. | ||
308 | AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], | ||
309 | gl_cv_func_mbrtowc, | ||
310 | [AC_LINK_IFELSE( | ||
311 | [AC_LANG_PROGRAM( | ||
312 | [[#include <wchar.h>]], | ||
313 | [[wchar_t wc; | ||
314 | char const s[] = ""; | ||
315 | size_t n = 1; | ||
316 | mbstate_t state; | ||
317 | return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], | ||
318 | gl_cv_func_mbrtowc=yes, | ||
319 | gl_cv_func_mbrtowc=no)]) | ||
320 | if test $gl_cv_func_mbrtowc = yes; then | ||
321 | AC_DEFINE([HAVE_MBRTOWC], [1], | ||
322 | [Define to 1 if mbrtowc and mbstate_t are properly declared.]) | ||
323 | fi | ||
324 | ]) | ||
325 | ]) | ||