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