Commit 1ae48358 by Danny Smith Committed by Paolo Carlini

re PR libstdc++/20806 (basic_filebuf::xsgetn() fails with text mode and DOS…

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
parent db77171d
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> 2005-04-08 Kelley Cook <kcook@gcc.gnu.org>
* acconfig.h: Sort the bottom section. * acconfig.h: Sort the bottom section.
......
// Specific definitions for generic platforms -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -45,4 +45,7 @@ ...@@ -45,4 +45,7 @@
#undef NOMINMAX #undef NOMINMAX
#define NOMINMAX 1 #define NOMINMAX 1
// See libstdc++/20806.
#define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM 1
#endif #endif
// Specific definitions for newlib -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#ifdef __CYGWIN__ #ifdef __CYGWIN__
#define _GLIBCXX_GTHREAD_USE_WEAK 0 #define _GLIBCXX_GTHREAD_USE_WEAK 0
// See libstdc++/20806.
#define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM 1
#endif #endif
#endif #endif
...@@ -171,7 +171,15 @@ namespace std ...@@ -171,7 +171,15 @@ namespace std
// For a stateful encoding (-1) the pending sequence might be just // For a stateful encoding (-1) the pending sequence might be just
// shift and unshift prefixes with no actual character. // shift and unshift prefixes with no actual character.
__ret = this->egptr() - this->gptr(); __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) if (__check_facet(_M_codecvt).encoding() >= 0)
#endif
__ret += _M_file.showmanyc() / _M_codecvt->max_length(); __ret += _M_file.showmanyc() / _M_codecvt->max_length();
} }
return __ret; return __ret;
...@@ -521,10 +529,17 @@ namespace std ...@@ -521,10 +529,17 @@ namespace std
// future: when __n > __buflen we read directly instead of using the // future: when __n > __buflen we read directly instead of using the
// buffer repeatedly. // buffer repeatedly.
const bool __testin = _M_mode & ios_base::in; const bool __testin = _M_mode & ios_base::in;
const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 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() if (__n > __buflen && __check_facet(_M_codecvt).always_noconv()
&& __testin && !_M_writing) && __testin && !_M_writing)
#endif
{ {
// First, copy the chars already present in the buffer. // First, copy the chars already present in the buffer.
const streamsize __avail = this->egptr() - this->gptr(); const streamsize __avail = this->egptr() - this->gptr();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment