[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: closein, freadahead and ungetc
From: |
Bruno Haible |
Subject: |
Re: closein, freadahead and ungetc |
Date: |
Thu, 6 Mar 2008 22:41:46 +0100 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote:
> 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).
Yes, I agree with you that both pieces of information are needed. I came to
the same conclusion.
However, I would prefer API changes as follows:
- freadahead keeps its signature but returns the total buffered bytes count.
- freadptr is changed to also return the size of the buffer.
extern const char * freadptr (FILE *stream, size_t *sizep);
When the return value is non-NULL, *sizep is set to the size of the
buffer whose address is the return value.
This way, both uses are clearly separated.
> Do you want to me to go ahead and work on this change?
First, I would like to see the two bugs that you found handled in one way or
the other. I'll try to do something about it, but I have no Cygwin here for
testing.
Bruno