summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-04-19 01:01:56 +0200
committerBruno Haible <bruno@clisp.org>2023-04-19 01:07:24 +0200
commit6c28538c9d6bbf692ab12972de6cc035e54b0c67 (patch)
tree192b7cf854082a8ebc66f8bb81d88bc6acc1fb5f /m4
parent5c9f32c99a0ad5bb6977c4d416fd6835eeb4fad5 (diff)
downloadgnulib-6c28538c9d6bbf692ab12972de6cc035e54b0c67.tar.gz
wmemcmp: Work around ISO C compliance bug on several platforms.
* lib/wchar.in.h (wmemcmp): Consider REPLACE_WMEMCMP. * lib/wmemcmp-impl.h (wmemcmp): Don't assume that the two wide characters are in the range 0..INT_MAX. * m4/wmemcmp.m4 (gl_FUNC_WMEMCMP): Test whether wmemcmp works for all wide characters. Set REPLACE_WMEMCMP. * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WMEMCMP. * modules/wchar (Makefile.am): Substitute REPLACE_WMEMCMP. * modules/wmemcmp (configure.ac): Consider REPLACE_WMEMCMP. * doc/posix-functions/wmemcmp.texi: Mention the bug.
Diffstat (limited to 'm4')
-rw-r--r--m4/wchar_h.m43
-rw-r--r--m4/wmemcmp.m449
2 files changed, 50 insertions, 2 deletions
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4
index 8cc38ef804..dfd154f8e9 100644
--- a/m4/wchar_h.m4
+++ b/m4/wchar_h.m4
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
dnl Written by Eric Blake.
-# wchar_h.m4 serial 57
+# wchar_h.m4 serial 58
AC_DEFUN_ONCE([gl_WCHAR_H],
[
@@ -255,5 +255,6 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME])
REPLACE_WCSSTR=0; AC_SUBST([REPLACE_WCSSTR])
REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK])
+ REPLACE_WMEMCMP=0; AC_SUBST([REPLACE_WMEMCMP])
REPLACE_WMEMPCPY=0; AC_SUBST([REPLACE_WMEMPCPY])
])
diff --git a/m4/wmemcmp.m4 b/m4/wmemcmp.m4
index 534dde10cc..c804dc8a4a 100644
--- a/m4/wmemcmp.m4
+++ b/m4/wmemcmp.m4
@@ -1,4 +1,4 @@
-# wmemcmp.m4 serial 5
+# wmemcmp.m4 serial 6
dnl Copyright (C) 2011-2023 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_WMEMCMP],
[
AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
dnl We cannot use AC_CHECK_FUNCS here, because the MSVC 9 header files
dnl provide this function as an inline function definition.
AC_CACHE_CHECK([for wmemcmp], [gl_cv_func_wmemcmp],
@@ -21,5 +22,51 @@ AC_DEFUN([gl_FUNC_WMEMCMP],
])
if test $gl_cv_func_wmemcmp = no; then
HAVE_WMEMCMP=0
+ else
+ AC_CACHE_CHECK([whether wmemcmp works for all wide characters],
+ [gl_cv_func_wmemcmp_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+ #include <wchar.h>
+ int main ()
+ {
+ wchar_t a = (wchar_t) 0x76547654;
+ wchar_t b = (wchar_t) 0x9abc9abc;
+ int cmp = wmemcmp (&a, &b, 1);
+ if ((wchar_t)-1 < 0)
+ return !(cmp > 0);
+ else
+ return !(cmp < 0);
+ }
+ ]])
+ ],
+ [gl_cv_func_wmemcmp_works=yes],
+ [gl_cv_func_wmemcmp_works=no],
+ [case "$host_on" in
+ # Guess no on glibc versions < 2.15.
+ *-gnu* | gnu*)
+ AC_EGREP_CPP([Unlucky],
+ [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 15)
+ Unlucky GNU user
+ #endif
+#endif
+ ],
+ [gl_cv_func_wmemcmp_works="guessing no"],
+ [gl_cv_func_wmemcmp_works="guessing yes"])
+ ;;
+ # Guess no on musl systems.
+ *-musl* | midipix*) gl_cv_func_wmemcmp_works="guessing no" ;;
+ # If we don't know, obey --enable-cross-guesses.
+ *) gl_cv_func_wmemcmp_works="$gl_cross_guess_normal" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_wmemcmp_works" in
+ *yes) ;;
+ *) REPLACE_WMEMCMP=1 ;;
+ esac
fi
])