I want to get size of file in C (this program can handling open big input file >4GB). I use function fseek and ftell to get size of file. But the problem when we use this command is fseek and ftell can not handling open big file input (>4GB). Because return value from command ftell is an integer data type. If we want to get size of file (C program can handling open big file input) we can use function fseeko64 and ftello64. This function exist in header sys/types.h (I use Ubuntu Linux).
I will give an example how to get size of big file (C handling big file input) with use use function fseeko64 and ftello64. This program use input from stdin and compute size of file from that input file. Save this code as cbigfile.c :
int main(int argc, char **argv)
off64_t endPos; /*size of file input*/
off64_t bytetr; /*size of trace data and data */
retseek = fseeko64(stdin, 0 , SEEK_END); /* go to end of file */
printf("error seek command.");
endPos = ftello64(stdin); /* get size of file */
printf("size file from stdin = %lld byte\n", endPos);
Compile this C get size of big file code with command :
gcc cbigfile.c -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -o cbigfile
This is a sample output when this C program open and get size of big file (12GB).
./cbigfile < /data/Download/FILM/iso.iso
size file from stdin = 12905986806 byte
Thank for reading my post about how to open and get size of big file in C.Source : http://www.fedoraforum.org/forum/showthread.php?t=187982
My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.