[Python-Dev] End of the line

M.-A. Lemburg mal@lemburg.com
Sun, 18 Jul 1999 22:29:43 +0200


Tim Peters wrote:
> 
> Anyone know offhand if there's a reliable way to determine whether an open
> file descriptor (a C FILE*) is seekable?

I'd simply use trial&error:

if (fseek(stream,0,SEEK_CUR) < 0) {
	if (errno != EBADF)) {
		/* Not seekable */
		errno = 0;
	}
	else
		/* Error */
		;
}
else
	/* Seekable */
	;

How to get this thread safe is left as exercise to the interested
reader ;)

Cheers,
-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   166 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/