Re: [hatari-devel] Using ftello/fseeko instead of ftell/fseek for large file support

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Thorsten Otto schrieb:

> example:
> 
> you have a file that is 0x100001000LL bytes large and do:
> 
> if (fseeko(fp, 0L, SEEK_END) < 0)
>    return (off_t)-1;
> off_t size = ftello(fp);
> return size;
> 
> If the caller on the atari side assigns the return value to a long (32bit),
> it will be truncated to 0x1000, without noticing any error.

But as you yourself wrote earlier, "long" can also be 64 bit wide on
some platforms. So your example code above but with fseek/ftell and with
long instead of off_t will cause the same issue on these platforms when
the 64 bit long from the host side is cast to a 32 bit long on the Atari
side. Of course, return values must always be checked before passing
them to the Atari side, regardless of whether you use ftell or ftello.

Actually, are you thus suggesting that Windows is more safe because it
restricts the return values of ftell to 32 bits? ;-)

Regards
Christian
-- 
Christian Zietz  -  CHZ-Soft  -  czietz@xxxxxxx
WWW: http://www.chzsoft.de/
PGP/GnuPG-Key-ID: 0x52CB97F66DA025CA / 0x6DA025CA



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/