Bug 108967 - streambuf::in_avail() always returns zero
streambuf::in_avail() always returns zero
Product: Red Hat Linux
Classification: Retired
Component: libstdc++ (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2003-11-03 16:13 EST by Bob Shaffer
Modified: 2007-04-18 12:59 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-01 13:04:31 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Bob Shaffer 2003-11-03 16:13:05 EST
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):

How reproducible:

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 13:04:31 EDT
This isn't a bug. 

Default behavior: Returns zero.

If a read position is available, returns egptr() - gptr(). Otherwise
returns 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.


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