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
This commit is contained in:
Danny Smith 2005-04-08 17:31:33 +00:00 committed by Paolo Carlini
parent db77171de4
commit 1ae4835877
4 changed files with 36 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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();