[uClibc]fseek(3) idempotency

Erik Andersen andersen at codepoet.org
Mon Sep 24 22:45:11 UTC 2001


On Mon Sep 24, 2001 at 04:38:11PM -0600, Matt Kraai wrote:
> 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?

Pulling out my copy of Posix/IEEE 1003.1b-1993, and it seems to agree
with SuS2:

Some devices are incapable of seeking.  The value of the file offset associated
with such a device is undefined.  The behavior of the lseek() function on such
devices is implementation defined.

...Otherwise, it shall return a value of ((off_t)-1), shall set errno to
indicate the error, and the file offset shall remain unchanged by this function
call.

 -Erik

--
Erik B. Andersen   email:  andersee at debian.org, formerly of Lineo
--This message was written using 73% post-consumer electrons--





More information about the uClibc mailing list