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
]
On Mittwoch, 23. August 2017 17:33:27 CEST Nicolas Pomarède wrote:
> So, I think it would be safe to use fseeko/ftello everywhere, but as I
Actually, it is more safe to use the default functions in most cases. If you
pass a value that exceeds the 2GB limit to a function that handles only 32bit
offsets, you will get an error. Passing the same value to a function that can
handle 64bit succeeds. But if your caller (the atari disk driver or whatever)
can not handle it, you may end up truncating the 64bit value to a (valid)
32bit value, thus accessing totally wrong data.
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.