[Python-Dev] TELL64

Guido van Rossum guido@python.org
2001年1月15日 23:08:46 -0500


Looking at the code (in _portable_fseek()) that uses TELL64, I don't
understand why it can't use fgetpos(). That code is used only when
fpos_t -- the type used by fgetpos() and fsetpos() -- is 64-bit.
Trent, you wrote that code. Why wouldn't this work just as well?
(your code):
			if ((pos = TELL64(fileno(fp))) == -1L)
				return -1;
(my suggestion):
			if (fgetpos(fp, &pos) != 0)
				return -1;
It can't be because fgetpos() doesn't exist or is otherwise unusable,
because the SEEK_CUR case uses it.
We also know that offset is 8-bit capable (the #if around the
declaration of _portable_fseek() ensures that).
I would even go as far as to collapse the entire switch as follows:
	fpos_t pos;
	switch (whence) {
	case SEEK_END:
		/* do a "no-op" seek first to sync the buffering so that
		 the low-level tell() can be used correctly */
		if (fseek(fp, 0, SEEK_END) != 0)
			return -1;
		/* fall through */
	case SEEK_CUR:
		if (fgetpos(fp, &pos) != 0)
			return -1;
		offset += pos;
		break;
	/* case SEEK_SET: break; */
	}
	return fsetpos(fp, &offset);
--Guido van Rossum (home page: http://www.python.org/~guido/)

AltStyle によって変換されたページ (->オリジナル) /