Debian Codegraph @

m4/btowc.m4

raw
1 # btowc.m4
2 # serial 16
3 dnl Copyright (C) 2008-2026 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FUNC_BTOWC],
10 [
11 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12 AC_REQUIRE([gt_TYPE_WINT_T])
13
14 dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
15 dnl program below may lead to an endless loop. See
16 dnl <https://gcc.gnu.org/PR42440>.
17 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
18
19 AC_CHECK_FUNCS_ONCE([btowc])
20 if test $ac_cv_func_btowc = no; then
21 HAVE_BTOWC=0
22 else
23
24 AC_REQUIRE([AC_PROG_CC])
25 AC_REQUIRE([gt_LOCALE_FR])
26 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
27
28 dnl Cygwin 1.7.2 btowc('\0') is WEOF, not 0.
29 AC_CACHE_CHECK([whether btowc(0) is correct],
30 [gl_cv_func_btowc_nul],
31 [
32 AC_RUN_IFELSE(
33 [AC_LANG_SOURCE([[
34 #include <wchar.h>
35 int main ()
36 {
37 if (btowc ('\0') != 0)
38 return 1;
39 return 0;
40 }]])],
41 [gl_cv_func_btowc_nul=yes],
42 [gl_cv_func_btowc_nul=no],
43 [
44 changequote(,)dnl
45 case "$host_os" in
46 # Guess no on Cygwin.
47 cygwin*) gl_cv_func_btowc_nul="guessing no" ;;
48 # Guess yes on native Windows.
49 mingw* | windows*) gl_cv_func_btowc_nul="guessing yes" ;;
50 # Guess yes otherwise.
51 *) gl_cv_func_btowc_nul="guessing yes" ;;
52 esac
53 changequote([,])dnl
54 ])
55 ])
56
57 dnl On mingw, in the C locale, btowc is inconsistent with mbrtowc:
58 dnl mbrtowc avoids calling MultiByteToWideChar when MB_CUR_MAX is 1 and
59 dnl ___lc_codepage_func() is 0, but btowc is lacking this special case.
60 AC_CHECK_FUNCS_ONCE([mbrtowc])
61 AC_CACHE_CHECK([whether btowc is consistent with mbrtowc in the C locale],
62 [gl_cv_func_btowc_consistent],
63 [
64 AC_RUN_IFELSE(
65 [AC_LANG_SOURCE([[
66 #include <stdlib.h>
67 #include <string.h>
68 #include <wchar.h>
69 int main ()
70 {
71 #if HAVE_MBRTOWC
72 wint_t wc1 = btowc (0x80);
73 wchar_t wc2 = (wchar_t) 0xbadface;
74 char buf[1] = { 0x80 };
75 mbstate_t state;
76 memset (&state, 0, sizeof (mbstate_t));
77 if (mbrtowc (&wc2, buf, 1, &state) != 1 || wc1 != wc2)
78 return 1;
79 #endif
80 return 0;
81 }]])],
82 [gl_cv_func_btowc_consistent=yes],
83 [gl_cv_func_btowc_consistent=no],
84 [case "$host_os" in
85 # Guess no on mingw.
86 mingw* | windows*)
87 AC_EGREP_CPP([Problem], [
88 #ifdef __MINGW32__
89 Problem
90 #endif
91 ],
92 [gl_cv_func_btowc_consistent="guessing no"],
93 [gl_cv_func_btowc_consistent="guessing yes"])
94 ;;
95 # Guess yes otherwise.
96 *) gl_cv_func_btowc_consistent="guessing yes" ;;
97 esac
98 ])
99 ])
100
101 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
102 dnl On mingw/ucrt, we override the return type of btowc().
103 dnl While the original wint_t (= unsigned short) and the overridden wint_t
104 dnl (= unsigned int) are equivalent in function parameters, this is not
105 dnl the case for function return types.
106 REPLACE_BTOWC=1
107 fi
108 case "$gl_cv_func_btowc_nul" in
109 *yes) ;;
110 *) REPLACE_BTOWC=1 ;;
111 esac
112 case "$gl_cv_func_btowc_consistent" in
113 *yes) ;;
114 *) REPLACE_BTOWC=1 ;;
115 esac
116 if test $REPLACE_BTOWC = 0; then
117 gl_MBRTOWC_C_LOCALE
118 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
119 *yes) ;;
120 *) REPLACE_BTOWC=1 ;;
121 esac
122 fi
123 fi
124 ])
125
126 # Prerequisites of lib/btowc.c.
127 AC_DEFUN([gl_PREREQ_BTOWC], [
128 :
129 AC_CHECK_FUNCS_ONCE([mbrtowc])
130 ])