fstream.tcc (basic_filebuf::seekoff): Fix for output-only filebufs.
authorJason Merrill <jason@redhat.com>
Tue, 23 Apr 2002 21:56:10 +0000 (17:56 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 23 Apr 2002 21:56:10 +0000 (17:56 -0400)
        * 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.

From-SVN: r52685

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/include/std/std_fstream.h
libstdc++-v3/testsuite/27_io/ostream_seeks.cc

index c3667b9c7dda7dae4c256daeb1780cb7d0fd227e..bc892079c07ab2de29ad9ea50ae6bf891d3d4d2d 100644 (file)
@@ -1,5 +1,11 @@
 2002-04-23  Jason Merrill  <jason@redhat.com>
 
+       * 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.
index c530f34794b468d440625d8dd35739dc5395c8c5..6019cd1a02232fedb4f378a496648103d52dd8ec 100644 (file)
@@ -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;      
index c0d80da37c4c270ba0b79d69522b818a184921fe..0b20df19fa36f066fc1c98e5828acbf3a3a56e47 100644 (file)
@@ -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
index 7022a2f594f728bb83c08a97a63c3b73bb26063d..5afc675d2993c069db7fac6e7d73a7319707f73e 100644 (file)
@@ -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