]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Nathan C.
authorPaolo Carlini <pcarlini@unitus.it>
Thu, 26 Jun 2003 09:55:24 +0000 (11:55 +0200)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 26 Jun 2003 09:55:24 +0000 (09:55 +0000)
2003-06-26  Paolo Carlini  <pcarlini@unitus.it>
            Nathan C. Myers  <ncm-nospam@cantrip.org>

* include/bits/fstream.tcc (_M_underflow): When the actual
end of file is reached, set 'uncommitted' mode to allow a
next write without an intervening seek (see C++98 27.8.1.1,2
and C89 7.9.5.3).
* testsuite/27_io/basic_filebuf/underflow/char/2.cc: New.

Co-Authored-By: Nathan C. Myers <ncm-nospam@cantrip.org>
From-SVN: r68522

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc [new file with mode: 0644]

index 2a494a148b93fa2d0d3289c784f3590aecdf743f..4d244376d974c91803e99a6b59d38d25455faa89 100644 (file)
@@ -1,3 +1,12 @@
+2003-06-26  Paolo Carlini  <pcarlini@unitus.it>
+            Nathan C. Myers  <ncm-nospam@cantrip.org>
+
+       * include/bits/fstream.tcc (_M_underflow): When the actual
+       end of file is reached, set 'uncommitted' mode to allow a
+       next write without an intervening seek (see C++98 27.8.1.1,2
+       and C89 7.9.5.3).
+       * testsuite/27_io/basic_filebuf/underflow/char/2.cc: New.
+
 2003-06-25  Nathan C. Myers  <ncm-nospam@cantrip.org>
 
        * include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc,
index 22a24dcee69776941ae28c935d56a3d03e931ada..1568b6015fee7541e80a71890b7f40b6d9a9b5a2 100644 (file)
@@ -215,7 +215,7 @@ namespace std
            {
              char* __buf = static_cast<char*>(__builtin_alloca(__buflen));
              __elen = _M_file.xsgetn(__buf, __buflen);
-             
              const char* __eend;
              char_type* __iend;
              codecvt_base::result __r;
@@ -246,7 +246,15 @@ namespace std
              __ret = traits_type::to_int_type(*this->gptr());
              if (__bump)
                this->gbump(1);
-           }               
+           }
+         else if (__elen == 0)
+           {
+             // If the actual end of file is reached, set 'uncommitted'
+             // mode, thus allowing an immediate write without an 
+             // intervening seek.
+             _M_set_buffer(-1);
+             _M_reading = false;
+           }
        }
       _M_last_overflowed = false;      
       return __ret;
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc
new file mode 100644 (file)
index 0000000..8032a42
--- /dev/null
@@ -0,0 +1,48 @@
+// 2003-06-25 Paolo Carlini <pcarlini@unitus.it>
+
+// Copyright (C) 2003 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test = true;
+  using namespace std;
+
+  filebuf fb_out, fb_in_out;
+  
+  fb_out.open("tmp_underflow.tst", ios::out);
+  fb_out.sputc('S');
+  fb_out.sputc('T');
+  fb_out.close();
+
+  fb_in_out.open("tmp_underflow.tst", ios::in | ios::out);
+  while (fb_in_out.sbumpc() != filebuf::traits_type::eof());
+
+  VERIFY( fb_in_out.sputc('x') == 'x' );
+  fb_in_out.close();
+}
+
+int main()
+{
+  test01();
+}