[Python-Dev] TELL64

Trent Mick trentm@ActiveState.com
Tue, 16 Jan 2001 10:36:29 -0800


On Mon, Jan 15, 2001 at 11:08:46PM -0500, Guido van Rossum wrote:
> 
> 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;

I agree, that looks to me like it would. I guess I just missed that when I
wrote it.

> 
> 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);

Sure. Just get rid of the """do a "no-op" seek...""" comment because it is no
longer applicable. I am not setup to test this on Win64 right and I don't
suppose there are a lot of you out there with your own Win64 setups. I will
be able to test this before the scheduled 2.1 beta (late Feb), though.

Trent


-- 
Trent Mick
TrentM@ActiveState.com