|Re: [hatari-devel] Using ftello/fseeko instead of ftell/fseek for large file support|
[ Thread Index |
| More lists.tuxfamily.org/hatari-devel Archives
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Using ftello/fseeko instead of ftell/fseek for large file support
- From: David Savinkoff <dsavnkff@xxxxxxxxx>
- Date: Wed, 23 Aug 2017 12:29:38 -0600 (MDT)
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telus.net; s=neo; t=1503512978; bh=/1QutsHGIIDCvTKuDLyENAz570XwpsMDxk5LQVJkZfU=; h=Date:From:To:In-Reply-To:Subject; b=F9BYwBBCBnwLev23jBBuhbm0NgG0Nf894gX1NEoutqvuSVurv9jyegBuRMhSxKZxV OXxq19mtPIFD91qfUdJyq7f+X9oNO69rwyMYV6IYDAcYOWhwYWrtH95xh4BmyaB5oj qnWZCI9vPLLBkrKHJ/EzgwAiY+Syiwi/Wa63xn0lWuC2IcWTVSwMCPDBSOwxswoqJh BIAlo2IwODJZWKYf/NBv4Xch8KTW1Z3pIXb1MOP6iwzzv+ya4Syl5lZ4/2Z+/Z/WC+ In/LPV6WW8EYj9eV/RGg285GDfFwh7VEgA5CODcJHkygEIuOdHsMx4pw/dZBTxrXT+ +/wHyrLoIhy3g==
- Thread-index: 0KsCqeUXS8rjFb1ng7MvMCBSdwRCYw==
- Thread-topic: Using ftello/fseeko instead of ftell/fseek for large file support
----- Thorsten Otto wrote:
> 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.
> 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);
(size >= 1<<31) ? size = error_code() : size ;
> 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.
Since the Atari ST is known to handle integer 32 bit files, error checking
can be put into Hatari to prevent this problem. The MC68000 drivers
could have an error code (bus error?) passed to them by Hatari.
fseek() is defunct.