To my knowledge, there are no standard library functions that directly determine the size of the file. One way of determining file size would be to use fseek() and ftell() and examine the file pointer positions:
Code:
#include <stdio.h>
#include <limits.h>
int main( int argc, char** argv ) {
FILE* theFile = fopen( argv[1], "r" ); /* Open file, read only */
long int endPos;
fseek( theFile, 0, SEEK_END ); /* Place read pointer at an offset of 0 from end of file */
endPos = ftell( theFile );
printf( "Pointer position = %ld bytes from file start\n\n", endPos );
printf( "**********************************************\n");
printf( "Size of long int: %d\n", sizeof(long int) );
printf( "Maximum value of a long int: %ld\n", LONG_MAX );
printf( "File size, then, is limited to %ld MB\n", LONG_MAX / 1024 / 1024 );
printf( "**********************************************\n");
return 0;
}
On my computer, the output for a 23 byte file:
Pointer position = 23 bytes from file start
**********************************************
Size of long int: 4
Maximum value of a long int: 2147483647
File size, then, is limited to 2047 MB
**********************************************
The size of the file is constrained by the range of a long int, which is system dependent. You said you were checking for a 650MB file, so it shouldn't be a problem. However, if you need more, look into using fsetpos() and fgetpos().
Here's a site that explains fseek(), ftell() and the more capable fsetpos() and fgetpos():
http://www.opengroup.org/onlinepubs/...h/stdio.h.html
<EDIT>
Like I said, to the best of my knowledge. keefaz's suggestion to use stat is much better.
</EDIT>