Use Gnulib's `getaddrinfo' module.
[bpt/guile.git] / m4 / mbrlen.m4
CommitLineData
bfb18ff0 1# mbrlen.m4 serial 2
61cd9dc9 2dnl Copyright (C) 2008, 2009, 2010 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_MBRLEN],
8[
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 AC_REQUIRE([gl_FUNC_MBRTOWC])
13 AC_CHECK_FUNCS_ONCE([mbrlen])
14 if test $ac_cv_func_mbrlen = no; then
15 HAVE_MBRLEN=0
16 else
17 dnl Most bugs affecting the system's mbrtowc function also affect the
18 dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
19 dnl We could also run the individual tests below; the results would be
20 dnl the same.
21 if test $REPLACE_MBRTOWC = 1; then
22 REPLACE_MBRLEN=1
23 fi
24 fi
25 if test $HAVE_MBRLEN = 0 || test $REPLACE_MBRLEN = 1; then
26 gl_REPLACE_WCHAR_H
27 AC_LIBOBJ([mbrlen])
28 gl_PREREQ_MBRLEN
29 fi
30])
31
32dnl Test whether mbrlen puts the state into non-initial state when parsing an
33dnl incomplete multibyte character.
34dnl Result is gl_cv_func_mbrlen_incomplete_state.
35
36AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
37[
38 AC_REQUIRE([AC_PROG_CC])
39 AC_REQUIRE([gt_LOCALE_JA])
40 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
41 AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
42 [gl_cv_func_mbrlen_incomplete_state],
43 [
44 dnl Initial guess, used when cross-compiling or when no suitable locale
45 dnl is present.
46changequote(,)dnl
47 case "$host_os" in
48 # Guess no on AIX and OSF/1.
49 osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
50 # Guess yes otherwise.
51 *) gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
52 esac
53changequote([,])dnl
54 if test $LOCALE_JA != none; then
55 AC_TRY_RUN([
56#include <locale.h>
57#include <string.h>
58#include <wchar.h>
59int main ()
60{
61 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
62 {
63 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
64 mbstate_t state;
65
66 memset (&state, '\0', sizeof (mbstate_t));
67 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
68 if (mbsinit (&state))
69 return 1;
70 }
71 return 0;
72}],
73 [gl_cv_func_mbrlen_incomplete_state=yes],
74 [gl_cv_func_mbrlen_incomplete_state=no],
75 [])
76 fi
77 ])
78])
79
80dnl Test whether mbrlen, when parsing the end of a multibyte character,
81dnl correctly returns the number of bytes that were needed to complete the
82dnl character (not the total number of bytes of the multibyte character).
83dnl Result is gl_cv_func_mbrlen_retval.
84
85AC_DEFUN([gl_MBRLEN_RETVAL],
86[
87 AC_REQUIRE([AC_PROG_CC])
88 AC_REQUIRE([gt_LOCALE_FR_UTF8])
89 AC_REQUIRE([gt_LOCALE_JA])
90 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
91 AC_CACHE_CHECK([whether mbrlen has a correct return value],
92 [gl_cv_func_mbrlen_retval],
93 [
94 dnl Initial guess, used when cross-compiling or when no suitable locale
95 dnl is present.
96changequote(,)dnl
97 case "$host_os" in
98 # Guess no on HP-UX and Solaris.
99 hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
100 # Guess yes otherwise.
101 *) gl_cv_func_mbrlen_retval="guessing yes" ;;
102 esac
103changequote([,])dnl
104 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
105 AC_TRY_RUN([
106#include <locale.h>
107#include <string.h>
108#include <wchar.h>
109int main ()
110{
111 /* This fails on Solaris. */
112 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
113 {
114 char input[] = "B\303\274\303\237er"; /* "Büßer" */
115 mbstate_t state;
116
117 memset (&state, '\0', sizeof (mbstate_t));
118 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
119 {
120 input[1] = '\0';
121 if (mbrlen (input + 2, 5, &state) != 1)
122 return 1;
123 }
124 }
125 /* This fails on HP-UX 11.11. */
126 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
127 {
128 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
129 mbstate_t state;
130
131 memset (&state, '\0', sizeof (mbstate_t));
132 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
133 {
134 input[1] = '\0';
135 if (mbrlen (input + 2, 5, &state) != 2)
136 return 1;
137 }
138 }
139 return 0;
140}],
141 [gl_cv_func_mbrlen_retval=yes],
142 [gl_cv_func_mbrlen_retval=no],
143 [])
144 fi
145 ])
146])
147
148dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
149dnl Result is gl_cv_func_mbrlen_nul_retval.
150
151AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
152[
153 AC_REQUIRE([AC_PROG_CC])
154 AC_REQUIRE([gt_LOCALE_ZH_CN])
155 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
156 AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
157 [gl_cv_func_mbrlen_nul_retval],
158 [
159 dnl Initial guess, used when cross-compiling or when no suitable locale
160 dnl is present.
161changequote(,)dnl
162 case "$host_os" in
163 # Guess no on Solaris 9.
164 solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
165 # Guess yes otherwise.
166 *) gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
167 esac
168changequote([,])dnl
169 if test $LOCALE_ZH_CN != none; then
170 AC_TRY_RUN([
171#include <locale.h>
172#include <string.h>
173#include <wchar.h>
174int main ()
175{
176 /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030. */
177 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
178 {
179 mbstate_t state;
180
181 memset (&state, '\0', sizeof (mbstate_t));
182 if (mbrlen ("", 1, &state) != 0)
183 return 1;
184 }
185 return 0;
186}],
187 [gl_cv_func_mbrlen_nul_retval=yes],
188 [gl_cv_func_mbrlen_nul_retval=no],
189 [])
190 fi
191 ])
192])
193
194# Prerequisites of lib/mbrlen.c.
195AC_DEFUN([gl_PREREQ_MBRLEN], [
196 :
197])