diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c3667b9c7dd..bc892079c07 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2002-04-23 Jason Merrill + * include/bits/fstream.tcc (basic_filebuf::seekoff): Fix for + output-only filebufs. + * include/std/std_fstream.h (basic_filebuf::_M_set_indeterminate): + Likewise. + (basic_filebuf::_M_set_determinate): Likewise. + PR libstdc++/6414 * include/bits/fstream.tcc (basic_filebuf::seekoff): Adjust return value properly in the trivial case. diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index c530f34794b..6019cd1a022 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -567,7 +567,7 @@ namespace std else { __ret = _M_file.seekoff(__off, ios_base::cur, __mode); - __ret += _M_in_cur - _M_filepos; + __ret += max(_M_out_cur, _M_in_cur) - _M_filepos; } } _M_last_overflowed = false; diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h index c0d80da37c4..0b20df19fa3 100644 --- a/libstdc++-v3/include/std/std_fstream.h +++ b/libstdc++-v3/include/std/std_fstream.h @@ -264,7 +264,7 @@ namespace std this->setg(_M_buf, _M_buf, _M_buf); if (_M_mode & ios_base::out) this->setp(_M_buf, _M_buf); - _M_filepos = _M_in_end; + _M_filepos = _M_buf; } void @@ -276,7 +276,7 @@ namespace std this->setg(_M_buf, _M_buf, _M_buf + __off); if (__testout) this->setp(_M_buf, _M_buf + __off); - _M_filepos = _M_in_end; + _M_filepos = _M_buf + __off; } bool diff --git a/libstdc++-v3/testsuite/27_io/ostream_seeks.cc b/libstdc++-v3/testsuite/27_io/ostream_seeks.cc index 7022a2f594f..5afc675d299 100644 --- a/libstdc++-v3/testsuite/27_io/ostream_seeks.cc +++ b/libstdc++-v3/testsuite/27_io/ostream_seeks.cc @@ -167,6 +167,13 @@ void test04(void) pos06 = is03.tellp(); VERIFY( pos05 == pos06 ); + // libstdc++/6414 + if01.seekg(0, std::ios_base::beg); + pos01 = if01.tellg(); + if01.peek(); + pos02 = if01.tellg(); + VERIFY( pos02 == pos01 ); + #ifdef DEBUG_ASSERT assert(test); #endif