This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] libstdc++/9701 (in_avail() part)
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Apr 2003 00:46:16 +0200
- Subject: [v3] libstdc++/9701 (in_avail() part)
Hi,
tested x86-linux, reviewed by Benjamin.
Paolo.
////////
2003-04-14 Nathan Myers <ncm at cantrip dot org>
Paolo Carlini <pcarlini at unitus dot it>
PR libstdc++/9701 (in_avail())
* include/std/std_streambuf.h (in_avail): Simplify, in_avail
doesn't care if there is anything in some putback cell.
* testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc: Add.
* testsuite/27_io/basic_filebuf/in_avail/char/1.cc: Remove some
unused string literals.
diff -urN libstdc++-v3-orig/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
--- libstdc++-v3-orig/include/std/std_streambuf.h 2003-04-12 20:54:13.000000000 +0200
+++ libstdc++-v3/include/std/std_streambuf.h 2003-04-14 22:06:19.000000000 +0200
@@ -403,21 +403,8 @@
streamsize
in_avail()
{
- streamsize __ret;
- if (_M_in_cur && _M_in_cur < _M_in_end)
- {
- if (_M_pback_init)
- {
- size_t __save_len = _M_pback_end_save - _M_pback_cur_save;
- size_t __pback_len = _M_in_cur - _M_pback;
- __ret = __save_len - __pback_len;
- }
- else
- __ret = this->egptr() - this->gptr();
- }
- else
- __ret = this->showmanyc();
- return __ret;
+ streamsize __ret = _M_in_end - _M_in_cur;
+ return __ret ? __ret : this->showmanyc();
}
/**
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/in_avail/char/1.cc libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/in_avail/char/1.cc 2003-04-12 18:25:30.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc 2003-04-14 22:16:10.000000000 +0200
@@ -44,11 +44,6 @@
const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create
const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create
-const char name_04[] = "filebuf_virtuals-4.txt"; // empty file, need to create
-const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create
-const char name_06[] = "filebuf_virtuals-6.txt"; // empty file, need to create
-const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create
-const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create
class derived_filebuf: public std::filebuf
{
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc 2003-04-14 22:38:06.000000000 +0200
@@ -0,0 +1,59 @@
+// 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.5.2.2.3 Get area
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Derived_fbuf : public std::filebuf
+{
+public:
+ const char_type* pub_egptr() const
+ { return egptr(); }
+
+ const char_type* pub_gptr() const
+ { return gptr(); }
+};
+
+// libstdc++/9701 (partial)
+void test01()
+{
+ using namespace std;
+ bool test = true;
+ const char* name = "tmp_file1";
+
+ Derived_fbuf df2;
+ df2.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+
+ df2.sputn("Comomoc", 7);
+
+ df2.pubseekoff(0, ios_base::beg);
+ df2.sbumpc();
+ df2.sputbackc('t');
+
+ VERIFY( df2.pub_gptr() < df2.pub_egptr() );
+ VERIFY( df2.in_avail() == df2.pub_egptr() - df2.pub_gptr() );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}