diff options
author | Bruno Haible <bruno@clisp.org> | 2023-04-19 02:14:09 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-04-19 02:39:36 +0200 |
commit | 4b440d3568b01dd9acd5242bea8b63fc43428f5a (patch) | |
tree | 58e1ba3d97e79f2e21b73badab54a3b5b6d277d5 /lib | |
parent | 7634eee7a8da4a2f5eb9522ec01d24b8ad105df7 (diff) | |
download | gnulib-4b440d3568b01dd9acd5242bea8b63fc43428f5a.tar.gz |
wcscmp: Work around two ISO C compliance bugs on several platforms.
* lib/wchar.in.h (wcscmp): Consider REPLACE_WCSCMP.
* lib/wcscmp-impl.h (wcscmp): Don't assume that the two wide characters
are in the range 0..INT_MAX.
* m4/wcscmp.m4 (gl_FUNC_WCSCMP): Test whether wcscmp works for all wide
characters. Set REPLACE_WCSCMP.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSCMP.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSCMP.
* modules/wcscmp (Status, Notice): Un-obsolete this module.
(configure.ac): Consider REPLACE_WCSCMP.
* doc/posix-functions/wcscmp.texi: Mention the two bugs.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/wchar.in.h | 14 | ||||
-rw-r--r-- | lib/wcscmp-impl.h | 5 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 6a5b18d39d..c347256368 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -938,11 +938,21 @@ _GL_WARN_ON_USE (wcsncat, "wcsncat is unportable - " /* Compare S1 and S2. */ #if @GNULIB_WCSCMP@ -# if !@HAVE_WCSCMP@ +# if @REPLACE_WCSCMP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcscmp +# define wcscmp rpl_wcscmp +# endif +_GL_FUNCDECL_RPL (wcscmp, int, (const wchar_t *s1, const wchar_t *s2) + _GL_ATTRIBUTE_PURE); +_GL_CXXALIAS_RPL (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)); +# else +# if !@HAVE_WCSCMP@ _GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2) _GL_ATTRIBUTE_PURE); -# endif +# endif _GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)); +# endif # if __GLIBC__ >= 2 _GL_CXXALIASWARN (wcscmp); # endif diff --git a/lib/wcscmp-impl.h b/lib/wcscmp-impl.h index ba96db4f77..bc17c75d94 100644 --- a/lib/wcscmp-impl.h +++ b/lib/wcscmp-impl.h @@ -24,8 +24,9 @@ wcscmp (const wchar_t *s1, const wchar_t *s2) wchar_t wc2 = *s2++; if (wc1 != (wchar_t)'\0' && wc1 == wc2) continue; - /* Note that wc1 and wc2 each have at most 31 bits. */ - return (int)wc1 - (int)wc2; + /* ISO C requires wcscmp to work with all wchar_t values. + We cannot assume that wc1 and wc2 are in the range 0..INT_MAX. */ + return _GL_CMP (wc1, wc2); /* > 0 if wc1 > wc2, < 0 if wc1 < wc2, = 0 if wc1 and wc2 are both '\0'. */ } |