PDA

View Full Version : struct stat64 problem, please help


hpn
30th September 2006, 10:16
I have an annoying problem with GCC and C, so if some of the coding gurus here is kind enough to help It will be much appreciated, cause extensive googling failed.
(I'm under Windows XP, CPU 32-bit Athlon XP., gcc version 3.4.5, mingw special)

Is there some simple way to return the size of a large file (2GB+) without opening it? GCC seems to not understand "struct stat64" (missing in the header "sys/stat.h")

Coding something like:

struct stat64 statbf;

returns a "storage size of 'statbf' isn't known" error.

My lame workaround is to open the large file:

FILE *f;
uint64_t size;
f = fopen64( nm, "rb" );
fseeko64( f, 0L, 2 );
size = ftello64( f );
fclose( f );

but opening just to get the size seems hacky plus it's about 10 times slower than using "struct stat" and statbf.st_size when processing a tree with thousands of files.

Thanks

Nic
30th September 2006, 13:53
try using __stat64 instead of stat64. Or maybe do a #define or typedef to use __stat64 instead of stat64 if compiling with MinGW.

-Nic

hpn
1st October 2006, 07:38
Thank you, Nic! Using __stat64 instead of stat64 does the trick.

I also had to rename the function that loads to &statbf from stat64 to _stat64:

_stat64(filename, &statbf )

The declaration of _stat64 is also in the header "sys/stat.h"

So here it is the correct solution:

struct __stat64 statbf;
uint64_t size;

_stat64( filename, &statbf );
size = statbf.st_size;

Pretty ugly looking though :)