Debian Codegraph @

m4/btowc.m4

raw
1 # btowc.m4 serial 13
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_BTOWC],
8 [
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11 dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
12 dnl program below may lead to an endless loop. See
13 dnl <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>.
14 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
15
16 AC_CHECK_FUNCS_ONCE([btowc])
17 if test $ac_cv_func_btowc = no; then
18 HAVE_BTOWC=0
19 else
20
21 AC_REQUIRE([AC_PROG_CC])
22 AC_REQUIRE([gt_LOCALE_FR])
23 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24
25 dnl Cygwin 1.7.2 btowc('\0') is WEOF, not 0.
26 AC_CACHE_CHECK([whether btowc(0) is correct],
27 [gl_cv_func_btowc_nul],
28 [
29 AC_RUN_IFELSE(
30 [AC_LANG_SOURCE([[
31 #include <wchar.h>
32 int main ()
33 {
34 if (btowc ('\0') != 0)
35 return 1;
36 return 0;
37 }]])],
38 [gl_cv_func_btowc_nul=yes],
39 [gl_cv_func_btowc_nul=no],
40 [
41 changequote(,)dnl
42 case "$host_os" in
43 # Guess no on Cygwin.
44 cygwin*) gl_cv_func_btowc_nul="guessing no" ;;
45 # Guess yes on native Windows.
46 mingw*) gl_cv_func_btowc_nul="guessing yes" ;;
47 # Guess yes otherwise.
48 *) gl_cv_func_btowc_nul="guessing yes" ;;
49 esac
50 changequote([,])dnl
51 ])
52 ])
53
54 dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF.
55 AC_CACHE_CHECK([whether btowc(EOF) is correct],
56 [gl_cv_func_btowc_eof],
57 [
58 dnl Initial guess, used when cross-compiling or when no suitable locale
59 dnl is present.
60 changequote(,)dnl
61 case "$host_os" in
62 # Guess no on IRIX.
63 irix*) gl_cv_func_btowc_eof="guessing no" ;;
64 # Guess yes on native Windows.
65 mingw*) gl_cv_func_btowc_eof="guessing yes" ;;
66 # Guess yes otherwise.
67 *) gl_cv_func_btowc_eof="guessing yes" ;;
68 esac
69 changequote([,])dnl
70 if test $LOCALE_FR != none; then
71 AC_RUN_IFELSE(
72 [AC_LANG_SOURCE([[
73 #include <locale.h>
74 #include <stdio.h>
75 #include <wchar.h>
76 int main ()
77 {
78 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
79 {
80 if (btowc (EOF) != WEOF)
81 return 1;
82 }
83 return 0;
84 }]])],
85 [gl_cv_func_btowc_eof=yes],
86 [gl_cv_func_btowc_eof=no],
87 [:])
88 fi
89 ])
90
91 dnl On mingw, in the C locale, btowc is inconsistent with mbrtowc:
92 dnl mbrtowc avoids calling MultiByteToWideChar when MB_CUR_MAX is 1 and
93 dnl ___lc_codepage_func() is 0, but btowc is lacking this special case.
94 AC_CHECK_FUNCS_ONCE([mbrtowc])
95 AC_CACHE_CHECK([whether btowc is consistent with mbrtowc in the C locale],
96 [gl_cv_func_btowc_consistent],
97 [
98 AC_RUN_IFELSE(
99 [AC_LANG_SOURCE([[
100 #include <stdlib.h>
101 #include <string.h>
102 #include <wchar.h>
103 int main ()
104 {
105 #if HAVE_MBRTOWC
106 wint_t wc1 = btowc (0x80);
107 wchar_t wc2 = (wchar_t) 0xbadface;
108 char buf[1] = { 0x80 };
109 mbstate_t state;
110 memset (&state, 0, sizeof (mbstate_t));
111 if (mbrtowc (&wc2, buf, 1, &state) != 1 || wc1 != wc2)
112 return 1;
113 #endif
114 return 0;
115 }]])],
116 [gl_cv_func_btowc_consistent=yes],
117 [gl_cv_func_btowc_consistent=no],
118 [case "$host_os" in
119 # Guess no on mingw.
120 mingw*) AC_EGREP_CPP([Problem], [
121 #ifdef __MINGW32__
122 Problem
123 #endif
124 ],
125 [gl_cv_func_btowc_consistent="guessing no"],
126 [gl_cv_func_btowc_consistent="guessing yes"])
127 ;;
128 # Guess yes otherwise.
129 *) gl_cv_func_btowc_consistent="guessing yes" ;;
130 esac
131 ])
132 ])
133
134 case "$gl_cv_func_btowc_nul" in
135 *yes) ;;
136 *) REPLACE_BTOWC=1 ;;
137 esac
138 case "$gl_cv_func_btowc_eof" in
139 *yes) ;;
140 *) REPLACE_BTOWC=1 ;;
141 esac
142 case "$gl_cv_func_btowc_consistent" in
143 *yes) ;;
144 *) REPLACE_BTOWC=1 ;;
145 esac
146 if test $REPLACE_BTOWC = 0; then
147 gl_MBRTOWC_C_LOCALE
148 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
149 *yes) ;;
150 *) REPLACE_BTOWC=1 ;;
151 esac
152 fi
153 fi
154 ])
155
156 # Prerequisites of lib/btowc.c.
157 AC_DEFUN([gl_PREREQ_BTOWC], [
158 :
159 AC_CHECK_FUNCS_ONCE([mbrtowc])
160 ])