bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: closein, freadahead and ungetc


From: Eric Blake
Subject: Re: closein, freadahead and ungetc
Date: Thu, 06 Mar 2008 06:41:04 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080213 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 2/29/2008 6:36 AM:
| According to Bruno Haible on 2/29/2008 3:49 AM:
| | With strace you can see that there is only a single read() from the file
| | descriptor. I.e. at the moment when freadahead() returns 0, it is only
| | the ungetc-backup-buffer which has been emptied; the main buffer still
| | contains 685 bytes.
| |
| | Where to fix this? In closein.c? Or in freadahead.c?
|
| It seems like freadahead should add together the length of the ungetc
| buffer and the read buffer, if we can easily get to both those pieces of
| information - the contract of freadahead is that it tries to report how
| many bytes can be read from the stream without requiring another
| underlying read().

After more thought, I think we need an API change to freadahead, to add a
flag parameter.  When the flag is 0, return the number of bytes available
in the current buffer that freadptr would return.  When the flag is
non-zero, return the number of bytes available prior to the next necessary
underlying read() (ie. the ungetc buffer size + the cached read() buffer
size).

Both pieces of information are needed.  The size of the current buffer is
important to freadptr() clients (returning the sum of both available
buffers is wrong, since you would then be reading beyond the bounds of the
ungetc buffer).  The size of the total cached data is important to closein
(if there is any uncached data at all, whether it is ungetc data or not,
then the flush needs to be performed).

Do you want to me to go ahead and work on this change?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHz/Rv84KuGfSFAYARAt1WAKCQphBIV8oBzrtEDfH79GCWwKLBOQCcCHxF
tz+kMRXLKFF6ouRoEO21i1M=
=kXti
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]