Provide easier configure options for GMP and readline
[bpt/guile.git] / m4 / mbrtowc.m4
CommitLineData
f240aacb
LC
1# mbrtowc.m4 serial 15
2dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, Inc.
bfb18ff0
NJ
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_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
53dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
54dnl redefines the semantics of the given mbstate_t type.
55dnl Result is REPLACE_MBSTATE_T.
56dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
57dnl avoid inconsistencies.
58
59AC_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
f240aacb
LC
68 gl_MBRTOWC_SANITYCHECK
69 REPLACE_MBSTATE_T=0
bfb18ff0 70 case "$gl_cv_func_mbrtowc_incomplete_state" in
f240aacb
LC
71 *yes) ;;
72 *) REPLACE_MBSTATE_T=1 ;;
73 esac
74 case "$gl_cv_func_mbrtowc_sanitycheck" in
75 *yes) ;;
76 *) REPLACE_MBSTATE_T=1 ;;
bfb18ff0
NJ
77 esac
78 else
79 REPLACE_MBSTATE_T=1
80 fi
81 if test $REPLACE_MBSTATE_T = 1; then
82 gl_REPLACE_WCHAR_H
83 fi
84])
85
86dnl Test whether mbrtowc puts the state into non-initial state when parsing an
87dnl incomplete multibyte character.
88dnl Result is gl_cv_func_mbrtowc_incomplete_state.
89
90AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
91[
92 AC_REQUIRE([AC_PROG_CC])
93 AC_REQUIRE([gt_LOCALE_JA])
94 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
95 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
96 [gl_cv_func_mbrtowc_incomplete_state],
97 [
98 dnl Initial guess, used when cross-compiling or when no suitable locale
99 dnl is present.
100changequote(,)dnl
101 case "$host_os" in
102 # Guess no on AIX and OSF/1.
103 osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
104 # Guess yes otherwise.
105 *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
106 esac
107changequote([,])dnl
108 if test $LOCALE_JA != none; then
109 AC_TRY_RUN([
110#include <locale.h>
111#include <string.h>
112#include <wchar.h>
113int main ()
114{
115 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
116 {
117 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
118 mbstate_t state;
119 wchar_t wc;
120
121 memset (&state, '\0', sizeof (mbstate_t));
122 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
123 if (mbsinit (&state))
124 return 1;
125 }
126 return 0;
127}],
128 [gl_cv_func_mbrtowc_incomplete_state=yes],
129 [gl_cv_func_mbrtowc_incomplete_state=no],
f240aacb
LC
130 [:])
131 fi
132 ])
133])
134
135dnl Test whether mbrtowc works not worse than mbtowc.
136dnl Result is gl_cv_func_mbrtowc_sanitycheck.
137
138AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
139[
140 AC_REQUIRE([AC_PROG_CC])
141 AC_REQUIRE([gt_LOCALE_ZH_CN])
142 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
143 AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
144 [gl_cv_func_mbrtowc_sanitycheck],
145 [
146 dnl Initial guess, used when cross-compiling or when no suitable locale
147 dnl is present.
148changequote(,)dnl
149 case "$host_os" in
150 # Guess no on Solaris 8.
151 solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
152 # Guess yes otherwise.
153 *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
154 esac
155changequote([,])dnl
156 if test $LOCALE_ZH_CN != none; then
157 AC_TRY_RUN([
158#include <locale.h>
159#include <string.h>
160#include <wchar.h>
161int main ()
162{
163 /* This fails on Solaris 8:
164 mbrtowc returns 2, and sets wc to 0x00F0.
165 mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
166 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
167 {
168 char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
169 mbstate_t state;
170 wchar_t wc;
171
172 memset (&state, '\0', sizeof (mbstate_t));
173 if (mbrtowc (&wc, input + 3, 6, &state) != 4
174 && mbtowc (&wc, input + 3, 6) == 4)
175 return 1;
176 }
177 return 0;
178}],
179 [gl_cv_func_mbrtowc_sanitycheck=yes],
180 [gl_cv_func_mbrtowc_sanitycheck=no],
181 [:])
bfb18ff0
NJ
182 fi
183 ])
184])
185
186dnl Test whether mbrtowc supports a NULL string argument correctly.
187dnl Result is gl_cv_func_mbrtowc_null_arg.
188
189AC_DEFUN([gl_MBRTOWC_NULL_ARG],
190[
191 AC_REQUIRE([AC_PROG_CC])
192 AC_REQUIRE([gt_LOCALE_FR_UTF8])
193 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
194 AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
195 [gl_cv_func_mbrtowc_null_arg],
196 [
197 dnl Initial guess, used when cross-compiling or when no suitable locale
198 dnl is present.
199changequote(,)dnl
200 case "$host_os" in
201 # Guess no on OSF/1.
202 osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
203 # Guess yes otherwise.
204 *) gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
205 esac
206changequote([,])dnl
207 if test $LOCALE_FR_UTF8 != none; then
208 AC_TRY_RUN([
209#include <locale.h>
210#include <string.h>
211#include <wchar.h>
212int main ()
213{
214 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
215 {
216 mbstate_t state;
217 wchar_t wc;
218 int ret;
219
220 memset (&state, '\0', sizeof (mbstate_t));
221 wc = (wchar_t) 0xBADFACE;
222 mbrtowc (&wc, NULL, 5, &state);
223 /* Check that wc was not modified. */
224 if (wc != (wchar_t) 0xBADFACE)
225 return 1;
226 }
227 return 0;
f240aacb 228}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [:])
bfb18ff0
NJ
229 fi
230 ])
231])
232
233dnl Test whether mbrtowc, when parsing the end of a multibyte character,
234dnl correctly returns the number of bytes that were needed to complete the
235dnl character (not the total number of bytes of the multibyte character).
236dnl Result is gl_cv_func_mbrtowc_retval.
237
238AC_DEFUN([gl_MBRTOWC_RETVAL],
239[
240 AC_REQUIRE([AC_PROG_CC])
241 AC_REQUIRE([gt_LOCALE_FR_UTF8])
242 AC_REQUIRE([gt_LOCALE_JA])
243 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
244 AC_CACHE_CHECK([whether mbrtowc has a correct return value],
245 [gl_cv_func_mbrtowc_retval],
246 [
247 dnl Initial guess, used when cross-compiling or when no suitable locale
248 dnl is present.
249changequote(,)dnl
250 case "$host_os" in
251 # Guess no on HP-UX and Solaris.
252 hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
253 # Guess yes otherwise.
254 *) gl_cv_func_mbrtowc_retval="guessing yes" ;;
255 esac
256changequote([,])dnl
257 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
258 AC_TRY_RUN([
259#include <locale.h>
260#include <string.h>
261#include <wchar.h>
262int main ()
263{
264 /* This fails on Solaris. */
265 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
266 {
267 char input[] = "B\303\274\303\237er"; /* "Büßer" */
268 mbstate_t state;
269 wchar_t wc;
270
271 memset (&state, '\0', sizeof (mbstate_t));
272 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
273 {
274 input[1] = '\0';
275 if (mbrtowc (&wc, input + 2, 5, &state) != 1)
276 return 1;
277 }
278 }
279 /* This fails on HP-UX 11.11. */
280 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
281 {
282 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
283 mbstate_t state;
284 wchar_t wc;
285
286 memset (&state, '\0', sizeof (mbstate_t));
287 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
288 {
289 input[1] = '\0';
290 if (mbrtowc (&wc, input + 2, 5, &state) != 2)
291 return 1;
292 }
293 }
294 return 0;
295}],
296 [gl_cv_func_mbrtowc_retval=yes],
297 [gl_cv_func_mbrtowc_retval=no],
f240aacb 298 [:])
bfb18ff0
NJ
299 fi
300 ])
301])
302
303dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
304dnl Result is gl_cv_func_mbrtowc_nul_retval.
305
306AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
307[
308 AC_REQUIRE([AC_PROG_CC])
309 AC_REQUIRE([gt_LOCALE_ZH_CN])
310 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
311 AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
312 [gl_cv_func_mbrtowc_nul_retval],
313 [
314 dnl Initial guess, used when cross-compiling or when no suitable locale
315 dnl is present.
316changequote(,)dnl
317 case "$host_os" in
f240aacb
LC
318 # Guess no on Solaris 8 and 9.
319 solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
320 # Guess yes otherwise.
321 *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
bfb18ff0
NJ
322 esac
323changequote([,])dnl
324 if test $LOCALE_ZH_CN != none; then
325 AC_TRY_RUN([
326#include <locale.h>
327#include <string.h>
328#include <wchar.h>
329int main ()
330{
f240aacb 331 /* This fails on Solaris 8 and 9. */
bfb18ff0
NJ
332 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
333 {
334 mbstate_t state;
335 wchar_t wc;
336
337 memset (&state, '\0', sizeof (mbstate_t));
338 if (mbrtowc (&wc, "", 1, &state) != 0)
339 return 1;
340 }
341 return 0;
342}],
343 [gl_cv_func_mbrtowc_nul_retval=yes],
344 [gl_cv_func_mbrtowc_nul_retval=no],
f240aacb 345 [:])
bfb18ff0
NJ
346 fi
347 ])
348])
349
350# Prerequisites of lib/mbrtowc.c.
351AC_DEFUN([gl_PREREQ_MBRTOWC], [
352 :
353])
354
355
356dnl From Paul Eggert
357
358dnl This override of an autoconf macro can be removed when autoconf 2.60 or
359dnl newer can be assumed everywhere.
360
361m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[
362AC_DEFUN([AC_FUNC_MBRTOWC],
363[
364 dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
365 AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
366 gl_cv_func_mbrtowc,
367 [AC_LINK_IFELSE(
368 [AC_LANG_PROGRAM(
369 [[#include <wchar.h>]],
370 [[wchar_t wc;
371 char const s[] = "";
372 size_t n = 1;
373 mbstate_t state;
374 return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
375 gl_cv_func_mbrtowc=yes,
376 gl_cv_func_mbrtowc=no)])
377 if test $gl_cv_func_mbrtowc = yes; then
f240aacb 378 AC_DEFINE([HAVE_MBRTOWC], [1],
bfb18ff0
NJ
379 [Define to 1 if mbrtowc and mbstate_t are properly declared.])
380 fi
381])
382])