[uClibc]fseek(3) idempotency

Matt Kraai kraai at alumni.carnegiemellon.edu
Mon Sep 24 22:38:11 UTC 2001


On Mon, Sep 24, 2001 at 10:49:16AM -0600, Manuel Novoa III wrote:
> Something like the following _might_ work.  It needs testing though.
> 
> int is_seekable(FILE *fp)
> {
> 	/* Hope that the OS always returns an error for pipes or fifos */
> 	/* even when the offset is 0. */
> 	return ( lseek(fileno(fp),0,SEEK_CUR) >= 0 );
> }

This works in my tests.  I don't know if it is standards compliant
or not, however.

SUSv2 first states the following:

	The behaviour of lseek() on devices which are incapable of
	seeking is implementation-dependent.

and later says the following:

	Otherwise, (off_t)-1 is returned, errno is set to indicate
	the error and the file offset will remain unchanged. 

Do any of the other specifications make it any clearer?

Matt





More information about the uClibc mailing list