fseek problem files >2Gb (32-bit compile)

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
User avatar
Rebel
Posts: 4515
Joined: Thu Aug 18, 2011 10:04 am

fseek problem files >2Gb (32-bit compile)

Post by Rebel » Sat Apr 20, 2019 6:50 am

Code: Select all

FILE *fp;
int offset;
fseek(fp,offset,SEEK_SET);
When the file is >2Gb it crashes.

Changing int offset; to:

Code: Select all

unsigned int offset;
unsigned long long offset; (64 bit in my compiler)
Doesn't help, same crash.

Is there a way out?
Everybody is unique, except me.

User avatar
hgm
Posts: 23365
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: fseek problem files >2Gb (32-bit compile)

Post by hgm » Sat Apr 20, 2019 7:17 am


tmokonen
Posts: 1008
Joined: Sun Mar 12, 2006 5:46 pm
Location: Vancouver

Re: fseek problem files >2Gb (32-bit compile)

Post by tmokonen » Sat Apr 20, 2019 6:24 pm

Just be aware that _fseeki64 and _ftelli64 are Windows specific. I used the the more portable POSIX functions fseeko64 and ftello64 with GCC under windows successfully, although I am not sure they will work with Microsoft's compiler.

konsolas
Posts: 178
Joined: Sun Jun 12, 2016 3:44 pm
Location: London
Full name: Vincent
Contact:

Re: fseek problem files >2Gb (32-bit compile)

Post by konsolas » Sat Apr 20, 2019 6:34 pm

If you're on windows, you could also switch to c++ (std::ifstream supports all this natively) or use the windows API directly (CreateFile)

Post Reply