summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2005-04-08 17:31:33 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2005-04-08 17:31:33 +0000
commit1ae483587700e8c70bc488f12c92100fe15aab04 (patch)
treede5ca130869afa5dc643f8e2b96756dafddaa6fd
parentdb77171de4ffad95cbdf68a50a8d113c73cb3353 (diff)
downloadgcc-1ae483587700e8c70bc488f12c92100fe15aab04.tar.gz
re PR libstdc++/20806 (basic_filebuf::xsgetn() fails with text mode and DOS line endings and large buffers)
2005-04-08 Danny Smith <dannysmith@users.sourceforge.net> Paolo Carlini <pcarlini@suse.de> PR libstdc++/20806 * config/os/mingw32/os_defines.h: Define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM. * config/os/newlib/os_defines.h: Likewise, for __CYGWIN__. * include/bits/fstream.tcc (basic_filebuf<>::showmanyc()): Use it. (basic_filebuf<>::xsgetn(_CharT*, streamsize)): Likewise. Co-Authored-By: Paolo Carlini <pcarlini@suse.de> From-SVN: r97842
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/config/os/mingw32/os_defines.h5
-rw-r--r--libstdc++-v3/config/os/newlib/os_defines.h5
-rw-r--r--libstdc++-v3/include/bits/fstream.tcc19
4 files changed, 36 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index d42c83e6dd8..e92b927fac3 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2005-04-08 Danny Smith <dannysmith@users.sourceforge.net>
+ Paolo Carlini <pcarlini@suse.de>
+
+ PR libstdc++/20806
+ * config/os/mingw32/os_defines.h: Define
+ _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM.
+ * config/os/newlib/os_defines.h: Likewise, for __CYGWIN__.
+ * include/bits/fstream.tcc (basic_filebuf<>::showmanyc()):
+ Use it.
+ (basic_filebuf<>::xsgetn(_CharT*, streamsize)): Likewise.
+
2005-04-08 Kelley Cook <kcook@gcc.gnu.org>
* acconfig.h: Sort the bottom section.
diff --git a/libstdc++-v3/config/os/mingw32/os_defines.h b/libstdc++-v3/config/os/mingw32/os_defines.h
index 38fd3c711ac..20088868a39 100644
--- a/libstdc++-v3/config/os/mingw32/os_defines.h
+++ b/libstdc++-v3/config/os/mingw32/os_defines.h
@@ -1,6 +1,6 @@
// Specific definitions for generic platforms -*- C++ -*-
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -45,4 +45,7 @@
#undef NOMINMAX
#define NOMINMAX 1
+// See libstdc++/20806.
+#define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM 1
+
#endif
diff --git a/libstdc++-v3/config/os/newlib/os_defines.h b/libstdc++-v3/config/os/newlib/os_defines.h
index ff334610f22..0b0a6297955 100644
--- a/libstdc++-v3/config/os/newlib/os_defines.h
+++ b/libstdc++-v3/config/os/newlib/os_defines.h
@@ -1,6 +1,6 @@
// Specific definitions for newlib -*- C++ -*-
-// Copyright (C) 2000 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -35,6 +35,9 @@
#ifdef __CYGWIN__
#define _GLIBCXX_GTHREAD_USE_WEAK 0
+
+// See libstdc++/20806.
+#define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM 1
#endif
#endif
diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc
index a9d157403fe..6915ea9b23c 100644
--- a/libstdc++-v3/include/bits/fstream.tcc
+++ b/libstdc++-v3/include/bits/fstream.tcc
@@ -171,7 +171,15 @@ namespace std
// For a stateful encoding (-1) the pending sequence might be just
// shift and unshift prefixes with no actual character.
__ret = this->egptr() - this->gptr();
+
+#if _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM
+ // About this workaround, see libstdc++/20806.
+ const bool __testbinary = _M_mode & ios_base::binary;
+ if (__check_facet(_M_codecvt).encoding() >= 0
+ && __testbinary)
+#else
if (__check_facet(_M_codecvt).encoding() >= 0)
+#endif
__ret += _M_file.showmanyc() / _M_codecvt->max_length();
}
return __ret;
@@ -521,10 +529,17 @@ namespace std
// future: when __n > __buflen we read directly instead of using the
// buffer repeatedly.
const bool __testin = _M_mode & ios_base::in;
- const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1
- : 1;
+ const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1;
+
+#if _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM
+ // About this workaround, see libstdc++/20806.
+ const bool __testbinary = _M_mode & ios_base::binary;
+ if (__n > __buflen && __check_facet(_M_codecvt).always_noconv()
+ && __testin && __testbinary && !_M_writing)
+#else
if (__n > __buflen && __check_facet(_M_codecvt).always_noconv()
&& __testin && !_M_writing)
+#endif
{
// First, copy the chars already present in the buffer.
const streamsize __avail = this->egptr() - this->gptr();