+2009-09-08 Bruno Haible <bruno@clisp.org>
+
+ Work around towlower, towupper bug on mingw.
+ * lib/wctype.in.h (towlower, towupper) [__MINGW32__]: New replacements.
+ * m4/wctype.m4 (gl_WCTYPE_H): Replace <wctype.h> also on mingw.
+ * doc/posix-functions/towlower.texi: Mention the mingw bug.
+ * doc/posix-functions/towupper.texi: Likewise.
+ Reported by Eric Blake.
+
2009-09-08 Jim Meyering <meyering@redhat.com>
build: don't try to run autoheader if we don't use it
@item
This function is missing on some platforms:
IRIX 5.3, Solaris 2.5.1.
+@item
+This function returns values of which the upper 16 bits are incorrect
+on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
@item
This function is missing on some platforms:
IRIX 5.3, Solaris 2.5.1.
+@item
+This function returns values of which the upper 16 bits are incorrect
+on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
# endif /* ! HAVE_ISWCNTRL */
+# if defined __MINGW32__
+
+/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
+ The functions towlower and towupper are implemented in the MSVCRT library
+ to take a wchar_t argument and return a wchar_t result. mingw declares
+ these functions to take a wint_t argument and return a wint_t result.
+ This means that:
+ 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
+ function will look only at the lower 16 bits. This is allowed according
+ to POSIX.
+ 2. The return value is returned in the lower 16 bits of the result register.
+ The upper 16 bits are random: whatever happened to be in that part of the
+ result register. We need to fix this by adding a zero-extend from
+ wchar_t to wint_t after the call. */
+
+static inline wint_t
+rpl_towlower (wint_t wc)
+{
+ return (wint_t) (wchar_t) towlower (wc);
+}
+# define towlower rpl_towlower
+
+static inline wint_t
+rpl_towupper (wint_t wc)
+{
+ return (wint_t) (wchar_t) towupper (wc);
+}
+# define towupper rpl_towupper
+
+# endif
+
#endif /* _GL_WCTYPE_H */
#endif /* _GL_WCTYPE_H */
-# wctype.m4 serial 2
+# wctype.m4 serial 3
dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
AC_DEFUN([gl_WCTYPE_H],
[
AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_HOST])
AC_CHECK_FUNCS_ONCE([iswcntrl])
if test $ac_cv_func_iswcntrl = yes; then
HAVE_ISWCNTRL=1
])
])
if test $gl_cv_func_iswcntrl_works = yes; then
- WCTYPE_H=
+ case "$host_os" in
+ mingw*)
+ dnl On mingw, towlower and towupper return random high 16 bits.
+ ;;
+ *)
+ dnl iswcntrl works. towlower and towupper work as well.
+ WCTYPE_H=
+ ;;
+ esac
fi
fi
dnl Compute NEXT_WCTYPE_H even if WCTYPE_H is empty,