summaryrefslogtreecommitdiff
path: root/m4/mbrtoc32.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/mbrtoc32.m4')
-rw-r--r--m4/mbrtoc32.m4126
1 files changed, 79 insertions, 47 deletions
diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4
index 56f09c6d26..6303ec4601 100644
--- a/m4/mbrtoc32.m4
+++ b/m4/mbrtoc32.m4
@@ -1,5 +1,6 @@
-# mbrtoc32.m4 serial 6
-dnl Copyright (C) 2014-2021 Free Software Foundation, Inc.
+# mbrtoc32.m4
+# serial 18
+dnl Copyright (C) 2014-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -9,7 +10,10 @@ AC_DEFUN([gl_FUNC_MBRTOC32],
AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
AC_REQUIRE([AC_TYPE_MBSTATE_T])
- gl_MBSTATE_T_BROKEN
+ dnl Determine REPLACE_MBSTATE_T, from which GNULIB_defined_mbstate_t is
+ dnl determined. It describes how our overridden mbrtowc is implemented.
+ dnl We then implement mbrtoc32 accordingly.
+ AC_REQUIRE([gl_MBSTATE_T_BROKEN])
AC_REQUIRE([gl_TYPE_CHAR32_T])
AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
@@ -18,7 +22,7 @@ AC_DEFUN([gl_FUNC_MBRTOC32],
if test $gl_cv_func_mbrtoc32 = no; then
HAVE_MBRTOC32=0
else
- if test $GNULIB_OVERRIDES_CHAR32_T = 1 || test $REPLACE_MBSTATE_T = 1; then
+ if test $GNULIBHEADERS_OVERRIDE_CHAR32_T = 1 || test $REPLACE_MBSTATE_T = 1; then
REPLACE_MBRTOC32=1
else
gl_MBRTOC32_EMPTY_INPUT
@@ -44,25 +48,41 @@ AC_DEFUN([gl_FUNC_MBRTOC32],
fi
])
-dnl We can't use AC_CHECK_FUNC here, because mbrtoc32() is defined as a
-dnl static inline function on Haiku 2020.
AC_DEFUN([gl_CHECK_FUNC_MBRTOC32],
[
- AC_CACHE_CHECK([for mbrtoc32], [gl_cv_func_mbrtoc32],
- [AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <stdlib.h>
- #include <uchar.h>
- ]],
- [[char32_t c;
- return mbrtoc32 (&c, "", 1, NULL) == 0;
- ]])
- ],
- [gl_cv_func_mbrtoc32=yes],
- [gl_cv_func_mbrtoc32=no])
- ])
+ dnl Cf. gl_CHECK_FUNCS_ANDROID
+ AC_CHECK_DECL([mbrtoc32], , ,
+ [[#ifdef __HAIKU__
+ #include <stdint.h>
+ #endif
+ #include <uchar.h>
+ ]])
+ if test $ac_cv_have_decl_mbrtoc32 = yes; then
+ dnl We can't use AC_CHECK_FUNC here, because mbrtoc32() is defined as a
+ dnl static inline function on Haiku 2020.
+ AC_CACHE_CHECK([for mbrtoc32], [gl_cv_func_mbrtoc32],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdlib.h>
+ #ifdef __HAIKU__
+ #include <stdint.h>
+ #endif
+ #include <uchar.h>
+ ]],
+ [[char32_t c;
+ return mbrtoc32 (&c, "", 1, NULL) == 0;
+ ]])
+ ],
+ [gl_cv_func_mbrtoc32=yes],
+ [gl_cv_func_mbrtoc32=no])
+ ])
+ else
+ gl_cv_func_mbrtoc32=no
+ fi
])
+dnl Test whether mbrtoc32 returns the correct value on empty input.
+
AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT],
[
AC_REQUIRE([AC_PROG_CC])
@@ -70,17 +90,11 @@ AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT],
AC_CACHE_CHECK([whether mbrtoc32 works on empty input],
[gl_cv_func_mbrtoc32_empty_input],
[
- dnl Initial guess, used when cross-compiling or when no suitable locale
- dnl is present.
-changequote(,)dnl
- case "$host_os" in
- # Guess no on glibc systems.
- *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;;
- *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;;
- esac
-changequote([,])dnl
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
+ #ifdef __HAIKU__
+ #include <stdint.h>
+ #endif
#include <uchar.h>
static char32_t wc;
static mbstate_t mbs;
@@ -91,24 +105,36 @@ changequote([,])dnl
}]])],
[gl_cv_func_mbrtoc32_empty_input=yes],
[gl_cv_func_mbrtoc32_empty_input=no],
- [:])
+ [case "$host_os" in
+ # Guess no on glibc systems.
+ *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;;
+ # Guess no on Android.
+ linux*-android*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;;
+ # Guess no on native Windows.
+ mingw* | windows*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;;
+ *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;;
+ esac
+ ])
])
])
+dnl <https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrtowc.html>
+dnl POSIX:2018 says regarding mbrtowc: "In the POSIX locale an [EILSEQ] error
+dnl cannot occur since all byte values are valid characters." It is reasonable
+dnl to expect mbrtoc32 to behave in the same way.
+
AC_DEFUN([gl_MBRTOC32_C_LOCALE],
[
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether the C locale is free of encoding errors],
[gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ],
- [
- dnl Initial guess, used when cross-compiling or when no suitable locale
- dnl is present.
- gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="$gl_cross_guess_normal"
-
- AC_RUN_IFELSE(
+ [AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <limits.h>
#include <locale.h>
+ #ifdef __HAIKU__
+ #include <stdint.h>
+ #endif
#include <uchar.h>
]], [[
int i;
@@ -126,13 +152,14 @@ AC_DEFUN([gl_MBRTOC32_C_LOCALE],
}
return 0;
]])],
- [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=yes],
- [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=no],
- [case "$host_os" in
- # Guess yes on native Windows.
- mingw*) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="guessing yes" ;;
- esac
- ])
+ [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=yes],
+ [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=no],
+ [case "$host_os" in
+ # Guess yes on native Windows.
+ mingw* | windows*) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="guessing yes" ;;
+ *) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="$gl_cross_guess_normal" ;;
+ esac
+ ])
])
])
@@ -147,7 +174,7 @@ AC_DEFUN([gl_MBRTOC32_SANITYCHECK],
AC_REQUIRE([gt_LOCALE_FR])
AC_REQUIRE([gt_LOCALE_ZH_CN])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
- if test $GNULIB_OVERRIDES_CHAR32_T = 1 || test $gl_cv_func_mbrtoc32 = no; then
+ if test $GNULIBHEADERS_OVERRIDE_CHAR32_T = 1 || test $gl_cv_func_mbrtoc32 = no; then
HAVE_WORKING_MBRTOC32=0
else
AC_CACHE_CHECK([whether mbrtoc32 works as well as mbrtowc],
@@ -158,7 +185,7 @@ AC_DEFUN([gl_MBRTOC32_SANITYCHECK],
changequote(,)dnl
case "$host_os" in
# Guess no on FreeBSD, Solaris, native Windows.
- freebsd* | solaris* | mingw*)
+ freebsd* | midnightbsd* | solaris* | mingw* | windows*)
gl_cv_func_mbrtoc32_sanitycheck="guessing no"
;;
# Guess yes otherwise.
@@ -174,6 +201,9 @@ changequote([,])dnl
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
+#ifdef __HAIKU__
+ #include <stdint.h>
+#endif
#include <uchar.h>
int main ()
{
@@ -181,7 +211,8 @@ int main ()
/* This fails on native Windows:
mbrtoc32 returns (size_t)-1.
mbrtowc returns 1 (correct). */
- if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+ if (strcmp ("$LOCALE_FR", "none") != 0
+ && setlocale (LC_ALL, "$LOCALE_FR") != NULL)
{
mbstate_t state;
wchar_t wc = (wchar_t) 0xBADFACE;
@@ -194,10 +225,11 @@ int main ()
result |= 1;
}
}
- /* This fails on FreeBSD 12 and Solaris 11.4:
+ /* This fails on FreeBSD 13.0 and Solaris 11.4:
mbrtoc32 returns (size_t)-2 or (size_t)-1.
mbrtowc returns 4 (correct). */
- if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ if (strcmp ("$LOCALE_ZH_CN", "none") != 0
+ && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
{
mbstate_t state;
wchar_t wc = (wchar_t) 0xBADFACE;

Return to:

Send suggestions and report system problems to the System administrator.