[uClibc]fseek(3) idempotency

Manuel Novoa III mjn3 at uclibc.org
Tue Sep 25 18:48:14 UTC 2001


Matt,

On Tue, Sep 25, 2001 at 09:10:49AM -0600, Matt Kraai wrote:
> On Tue, Sep 25, 2001 at 08:35:37AM -0600, Manuel Novoa III wrote:
> > A couple of notes:
> > 
> > 1) I agree that there is no need in this case to invalidate the
> >    readahead buffer.  Regarding Matt's patch though, the
> >    "if (READING(fp))" test is unnecessary.  The assignment works
> >    for both reading or writing (although redundant here).
> 
> OK, then I'll commit the appropriately modified patch.  I'm an
> infrequent uClibc hacker, so I plead ignorance.

As I've had a new version of stdio on the back burner for a while now,
I haven't really looked at fixing anything in the current code.

> > 2) Even with this change, seek_sub_file() is still broken as fseek()
> >    will set the error flag for the FILE if it corresponds to a pipe
> >    or fifo, and subsequent reads should fail.  A clearerr() call
> >    needs to be done too.
> 
> Then fseek() isn't SUSv2 compliant:
> 
> 	... otherwise they return -1 and set errno to indicate the
> 	error.
> 
> Contrast this with the description for fread():
> 
> 	Otherwise, if a read error occurs, the error indicator for
> 	the stream is set and errno is set to indicate the error. 
>
> OK to also commit a patch which prevents fseek() from setting the
> error indicator?

Yes.  After rereading the standards, I agree that the stream error flag
shouldn't be set just because lseek fails.  Note though that the error
flag can be set indirectly by an fseek() call if it needs to flush any
buffered writes and the write call fails.  That is allowed by ANSI/ISO,
even if it isn't mentioned by SUSv2.

Manuel





More information about the uClibc mailing list