Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a file's size which is greater than 4 Gb?

Tags:

People also ask

Why is FAT32 limited to 4GB?

Why Are FAT32 Drives Limited to 4GB Files? Since FAT32 is 32-bit, the maximum possible value (all 1's) for that 32-bit field is 2^32, which counts to 4 Gigabytes. Hence FAT32 can support a maximum file size of 4GB.

How do I know how big my file size is?

Locate the file or folder whose size you would like to view. Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.


I made a simple function, which get's a file's size.

int file_size( char * filename )
{
     int size;
     struct stat st;

     stat( filename, &st );
     size = st.st_size;

     return size;

}//file_size

It is working fine, but if i have a file which size is bigger than 4Gb than i get a negativ number back, and of course this isn't the correct file size. So how can i get such a big file's size? I think, that the return value should anything else like int but i don't know what, and i don't think, that would solve my problem.

Thanks,

kampi

Update:

Hi!

I found the solution. I have to use __stat64. I modifyed my function, and now it is retrieving the real size. I tested it with an 8Gb big file.

unsigned long long int file_size( char * filename )
{
    unsigned long long int size;
    struct __stat64 st;

    __stat64( filename, &st );
    size = st.st_size;

   return size;

}//file_size

And a notice:

When i used printf, i had to use "%I64d" to print it out.