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

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

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

Post by Rebel »

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?
90% of coding is debugging, the other 10% is writing bugs.
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

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

Post by hgm »

tmokonen
Posts: 1296
Joined: Sun Mar 12, 2006 6:46 pm
Location: Kelowna
Full name: Tony Mokonen

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

Post by tmokonen »

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: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

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

Post by konsolas »

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