Bug 108967 - streambuf::in_avail() always returns zero
Summary: streambuf::in_avail() always returns zero
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: libstdc++
Version: 9
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL: http://www.cplusplus.com/ref/iostream...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-11-03 21:13 UTC by Bob Shaffer
Modified: 2007-04-18 16:59 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-10-01 17:04:31 UTC
Embargoed:


Attachments (Terms of Use)

Description Bob Shaffer 2003-11-03 21:13:05 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20030131

Description of problem:
The streambuf::in_avail() method always returns zero.  This simple
example program downloaded from cplusplus.com demonstrates the problem:

// in_avail () example
#include <iostream>
using namespace std;

int main () {

  streamsize size;
  char ch;

  streambuf * pbuf;
  pbuf = cin.rdbuf();

  cout << "Please enter some characters: ";
  cin >> ch;

  size = pbuf->in_avail();

  cout << "The first character you entered is: " << ch << endl;
  cout << size << " additional characters in input buffer" << endl;

  return 0;
}

// End of in_avail () example

When compiling and running on the supplied system/architecture, the
program will always report "0 additional characters in input buffer"
no matter how many there really are.  This is true for all stream
classes that use streambuf.


Version-Release number of selected component (if applicable):
libstdc++-3.2.2-5

How reproducible:
Always

Steps to Reproduce:
1. Compile the example code
2. Execute the example code
3. Enter a short phrase when prompted
    

Actual Results:  The first character entered is properly reported, and
"0 additional characters in input buffer" is always reported.

Expected Results:  The actual number of characters remaining in the
buffer being reported correctly.

Additional info:

This bug existed in previous standard c++ library packages. 
Considering that there is no other way to see if input is waiting on
an input stream, this problem really needs to be fixed.  It's not
really possible to use C++ streams in a good user interface as long as
this bug exists.

Comment 1 Benjamin Kosnik 2004-10-01 17:04:31 UTC
This isn't a bug. 

basic_streambuf::showmanyc
Default behavior: Returns zero.

basic_streambuf::in_avail()
If a read position is available, returns egptr() - gptr(). Otherwise
returns showmanyc()

filebuf::showmanyc();
Behaves the same as basic_streambuf::showmanyc()
Note:An implementation might well provide an overriding definition for
this function signature if it can determine that more characters can
be read from the input sequence.

This is implementation-specific behavior. 

If you want accurate in_avail semantics with GNU C++, you should use
streams with unbuffered io, ie std::basic_[io]fstream with a file
name. This will work as you expect.

best,
-benjamin


Note You need to log in before you can comment on or make changes to this bug.