diff options
author | Bruno Haible <bruno@clisp.org> | 2023-04-19 17:59:03 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-04-19 17:59:03 +0200 |
commit | ccb59e4c36bea4915303a24ea1c7dec109db97eb (patch) | |
tree | 30eb5e84cca4b21d1a18982cd5676fe80aaed08e /m4 | |
parent | 9bf6bcc74b4caf4d74bab8d98a4e00f761f2e5ca (diff) | |
download | gnulib-ccb59e4c36bea4915303a24ea1c7dec109db97eb.tar.gz |
wcsncmp: Work around two ISO C compliance bugs on several platforms.
* lib/wchar.in.h (wcsncmp): Consider REPLACE_WCSNCMP.
* lib/wcsncmp-impl.h (wcsncmp): Don't assume that the two wide
characters are in the range 0..INT_MAX.
* m4/wcsncmp.m4 (gl_FUNC_WCSNCMP): Test whether wcsncmp works for all
wide characters. Set REPLACE_WCSNCMP.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCMP.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSNCMP.
* modules/wcsncmp (Status, Notice): Un-obsolete this module.
(configure.ac): Consider REPLACE_WCSNCMP.
* doc/posix-functions/wcsncmp.texi: Mention the two bugs.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/wchar_h.m4 | 3 | ||||
-rw-r--r-- | m4/wcsncmp.m4 | 58 |
2 files changed, 59 insertions, 2 deletions
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index b9fa7cec84..442932be44 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 59 +# wchar_h.m4 serial 60 AC_DEFUN_ONCE([gl_WCHAR_H], [ @@ -254,6 +254,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME]) REPLACE_WCSCMP=0; AC_SUBST([REPLACE_WCSCMP]) + REPLACE_WCSNCMP=0; AC_SUBST([REPLACE_WCSNCMP]) REPLACE_WCSSTR=0; AC_SUBST([REPLACE_WCSSTR]) REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK]) REPLACE_WMEMCMP=0; AC_SUBST([REPLACE_WMEMCMP]) diff --git a/m4/wcsncmp.m4 b/m4/wcsncmp.m4 index 6253af3c22..4ef469f1ba 100644 --- a/m4/wcsncmp.m4 +++ b/m4/wcsncmp.m4 @@ -1,4 +1,4 @@ -# wcsncmp.m4 serial 2 +# wcsncmp.m4 serial 3 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, @@ -10,5 +10,61 @@ AC_DEFUN([gl_FUNC_WCSNCMP], AC_CHECK_FUNCS_ONCE([wcsncmp]) if test $ac_cv_func_wcsncmp = no; then HAVE_WCSNCMP=0 + else + AC_CACHE_CHECK([whether wcsncmp works for all wide characters], + [gl_cv_func_wcsncmp_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + #include <wchar.h> + int main () + { + int result = 0; + { /* This test fails on glibc < 2.15, musl libc 1.2.3, macOS 12.5, + FreeBSD 13.2, NetBSD 9.0, OpenBSD 7.2, Solaris 11.4. */ + wchar_t a[2] = { (wchar_t) 0x76547654, 0 }; + wchar_t b[2] = { (wchar_t) 0x9abc9abc, 0 }; + int cmp = wcsncmp (a, b, 1); + if (!((wchar_t)-1 < 0 ? cmp > 0 : cmp < 0)) + result |= 1; + } + { /* This test fails on AIX in 64-bit mode. */ + wchar_t c[2] = { (wchar_t) 'x', 0 }; + wchar_t d[3] = { (wchar_t) 'x', (wchar_t) 0x9abc9abc, 0 }; + int cmp = wcsncmp (c, d, 2); + if (!((wchar_t)-1 < 0 ? cmp > 0 : cmp < 0)) + result |= 2; + } + return result; + } + ]]) + ], + [gl_cv_func_wcsncmp_works=yes], + [gl_cv_func_wcsncmp_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_wcsncmp_works="guessing no"], + [gl_cv_func_wcsncmp_works="guessing yes"]) + ;; + # Guess no on musl systems. + *-musl* | midipix*) gl_cv_func_wcsncmp_works="guessing no" ;; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_wcsncmp_works="$gl_cross_guess_normal" ;; + esac + ]) + ]) + case "$gl_cv_func_wcsncmp_works" in + *yes) ;; + *) REPLACE_WCSNCMP=1 ;; + esac fi ]) |