This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/6746: ifstream::readsome() always returns zero


Synopsis: ifstream::readsome() always returns zero

State-Changed-From-To: analyzed->open
State-Changed-By: bkoz
State-Changed-When: Thu Jul  4 17:39:53 2002
State-Changed-Why:
    It looks like I am not going to be able to fix this before I leave. I'll resume looking at it after I get back, say July 23 rd ish...
    
    In sum, it looks like the patch to libstdc++/3647 was wrong.  At this point, rdbuf()->in_avail() is returning 0 for newly opened istreams (that are not empty.). This is incorrect.
    
    I suspect that the way to solve this is to set _M_buf and friends to real values instead of indeterminate values in filebuf's ctors. I did work up a partial solution to this based on this approach, but cannot find it at the moment.
    
    Here's another testcase for this
    
    #include <fstream>
    #include <sstream>
    #include <iostream>
    
    void test01()
    {
      using namespace std;
      streamsize sum = 0;
      istringstream iss("shamma shamma");
      
      // test01
      size_t i = iss.rdbuf()->in_avail();
      cout << i << endl;
    
      // test02
      size_t max = 0;
      while (iss.good() && max < 10)
        {
          char buf[1024];
          streamsize gotten = iss.readsome(buf, sizeof buf);
          sum += gotten;
          cout << gotten << " (" << sum << ")" << endl;
          ++max;
        }
    }
    
    void test02()
    {
      using namespace std;
      streamsize sum = 0;
      ifstream ifs(__FILE__);
      
      // test01
      size_t i = ifs.rdbuf()->in_avail();
      cout << i << endl;
    
      // test02
      size_t max = 0;
      while (ifs.good() && max < 10)
        {
          char buf[1024];
          streamsize gotten = ifs.readsome(buf, sizeof buf);
          sum += gotten;
          cout << gotten << " (" << sum << ")" << endl;
          ++max;
        }
    }
    
    int main()
    {
      test01();
      test02();
      return 0;
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6746


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]