From: Nathan Myers Date: Mon, 14 Apr 2003 22:43:32 +0000 (+0000) Subject: PR libstdc++/9701 (in_avail()) X-Git-Tag: releases/gcc-3.4.0~7294 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21a1d2c493e2d81e2adb0165bfeccfdaa963bd3f;p=thirdparty%2Fgcc.git PR libstdc++/9701 (in_avail()) 2003-04-14 Nathan Myers Paolo Carlini 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. Co-Authored-By: Paolo Carlini From-SVN: r65603 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 26d0095346dc..f43490cd9756 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2003-04-14 Nathan Myers + Paolo Carlini + + 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. + 2003-04-14 Paolo Carlini * include/bits/fstream.tcc (basic_filebuf::setbuf): Don't set diff --git a/libstdc++-v3/include/std/std_streambuf.h b/libstdc++-v3/include/std/std_streambuf.h index f6a31ac7c26a..62ea740da2a1 100644 --- a/libstdc++-v3/include/std/std_streambuf.h +++ b/libstdc++-v3/include/std/std_streambuf.h @@ -403,21 +403,8 @@ namespace std 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 --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc index 479ff7ba7078..306060e59370 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc @@ -44,11 +44,6 @@ const char carray_02[] = "memphis, new orleans, and savanah"; 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 --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc new file mode 100644 index 000000000000..4f98839d9072 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/9701-3.cc @@ -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 +#include + +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 (in_avail) +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; +}