From 222bd6c8493f3392c15db8cb3fe2e382063727d4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 21 Dec 2008 17:35:30 +0100 Subject: [PATCH] Work around a btowc() bug on IRIX 6.5. --- ChangeLog | 10 ++++++++ doc/posix-functions/btowc.texi | 3 +++ lib/wchar.in.h | 6 ++++- m4/btowc.m4 | 47 +++++++++++++++++++++++++++++++++- m4/wchar.m4 | 3 ++- modules/wchar | 1 + 6 files changed, 67 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9721f27d19..f6f6f65923 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-12-21 Bruno Haible + + Work around a btowc() bug on IRIX 6.5. + * lib/wchar.in.h (btowc): Override if REPLACE_BTOWC is set. + * m4/btowc.m4 (gl_FUNC_BTOWC): Test whether btowc(EOF) is correct. Set + REPLACE_WTOBC if not. + * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_BTOWC. + * modules/wchar (Makefile.am): Substitute REPLACE_BTOWC. + * doc/posix-functions/btowc.texi: Mention the IRIX bug. + 2008-12-21 Bruno Haible * modules/wcrtomb-tests: New file. diff --git a/doc/posix-functions/btowc.texi b/doc/posix-functions/btowc.texi index e54b29e5c5..b58fa848e8 100644 --- a/doc/posix-functions/btowc.texi +++ b/doc/posix-functions/btowc.texi @@ -11,6 +11,9 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: HP-UX 11.00, IRIX 5.3, Solaris 2.6, mingw, Interix 3.5. +@item +This function does not return WEOF for an EOF argument on some platforms: +IRIX 6.5. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 6bb9cbf8ed..8ef3ac82d5 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -84,7 +84,11 @@ typedef int rpl_mbstate_t; /* Convert a single-byte character to a wide character. */ #if @GNULIB_BTOWC@ -# if !@HAVE_BTOWC@ +# if @REPLACE_BTOWC@ +# undef btowc +# define btowc rpl_btowc +# endif +# if !@HAVE_BTOWC@ || @REPLACE_BTOWC@ extern wint_t btowc (int c); # endif #elif defined GNULIB_POSIXCHECK diff --git a/m4/btowc.m4 b/m4/btowc.m4 index a53694acd6..64ff829061 100644 --- a/m4/btowc.m4 +++ b/m4/btowc.m4 @@ -1,4 +1,4 @@ -# btowc.m4 serial 2 +# btowc.m4 serial 3 dnl Copyright (C) 2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -11,6 +11,51 @@ AC_DEFUN([gl_FUNC_BTOWC], AC_CHECK_FUNCS_ONCE([btowc]) if test $ac_cv_func_btowc = no; then HAVE_BTOWC=0 + else + + dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF. + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether btowc(EOF) is correct], + [gl_cv_func_btowc_eof], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on IRIX. + irix*) gl_cv_func_btowc_eof="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_btowc_eof="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR != none; then + AC_TRY_RUN([ +#include +#include +#include +#include +int main () +{ + if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) + { + if (btowc (EOF) != WEOF) + return 1; + } + return 0; +}], + [gl_cv_func_btowc_eof=yes], + [gl_cv_func_btowc_eof=no], + []) + fi + ]) + case "$gl_cv_func_btowc_eof" in + *yes) ;; + *) REPLACE_BTOWC=1 ;; + esac + fi + if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then gl_REPLACE_WCHAR_H AC_LIBOBJ([btowc]) gl_PREREQ_BTOWC diff --git a/m4/wchar.m4 b/m4/wchar.m4 index 40c43b7957..ef88cda551 100644 --- a/m4/wchar.m4 +++ b/m4/wchar.m4 @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. dnl Written by Eric Blake. -# wchar.m4 serial 17 +# wchar.m4 serial 18 AC_DEFUN([gl_WCHAR_H], [ @@ -81,6 +81,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) + REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC]) REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB]) REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT]) REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC]) diff --git a/modules/wchar b/modules/wchar index d829b3ab53..c0587cae96 100644 --- a/modules/wchar +++ b/modules/wchar @@ -45,6 +45,7 @@ wchar.h: wchar.in.h -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ + -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \ -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \ -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \ -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \ -- 2.30.2