int
File_size(char *path) {
FILE *fp;
if (fp = fopen(path, "r")) {
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fclose(fp);
return size;
}
return -1;
}
Refactorings
No refactoring yet !
Vidar Hokstad
August 5, 2009, August 05, 2009 19:52, permalink
Your example is limited to files up to 2GB; unfortunately I don't think you check for the size of larger files portably. If larger files matter to you, and you're on a Unix type platform, look at fseeko, lseek/lseek64, lstat.
Tj Holowaychuk
August 8, 2009, August 08, 2009 04:10, permalink
Nah shouldnt be an issue, good to know though
faster / better / sexier?