This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: A little more help ;)


On Wed, Mar 05, 2003 at 01:25:40AM +0100, Paolo Carlini wrote:
> I have got a prototype which already seems to work! (testsuite ok,
> all the new tests ok, 81920 chars read in P?tur QoI test ;)
> 
> However, 7744 seems not automatically fixed :(
> 
> void f2()
> {
>  cout
>  << "\n:: f2() ::\n"
>  << "Type in the characters 'abc' and press <ENTER>: ";
>  cin.peek();
>  cout
>  << "The number of unread characters should be 4 (a, b, c, \\n): "
>  << cin.rdbuf()->in_avail()
>  << '\n';
> }
> 
> what happens is that upon ::fstat(this->fd(), &__buffer),
> __buffer.st_size is zero.
> 
> Anything coming quickly to your mind?

I would not expect fstat to consider stdin to be a file.
(It looks like a "character special file".)  

Anyhow, the cin.peek() ought to call underflow(), which should do a 
::read(0,buf,8k), which should return 4 and put all four characters 
into the buffer.  Then in_avail() should report them, and shouldn't 
call showmanyc() at all, so ::fstat() should not even be called.  

(BTW, do you know the strace command?  E.g. try "strace /bin/echo foo"
and look at the last few lines.)

About the putback buffer: if a character has been put back
in the separate putback buffer, in_avail() should return 1.
After that character has been read out, in_avail() should 
find the buffer empty and call showmanyc(), which may fix up
the pointers and then report what's in the regular buffer and 
any more characters it can discover.  In other words, the 
putback buffer is involved in all virtuals, too.

Nathan Myers
ncm-nospam at cantrip dot org


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