how do you get the size of a file bigger than LONG_MAX in C?
I know you can use fopen+SEEK_END+ftell as long as your filesize don't exceed LONG_MAX, but what if it does?
#include <stdio.h>
int main(int argc, char **argv) {
FILE *fp;
fp = fopen(argv[0], "rb");
fseek(fp, 0, SEEK_END);
long fsize = ftell(fp);
fclose(fp);
printf("%ld\n", fsize);
}
in C++ i would use std::filesystem::file_size() returning std::uintmax_t
The comment suggests windows.
You have plenty of functions in Windows:
_fstat, _fstat32, _fstat64, _fstati64, _fstat32i64, _fstat64i32GetFileSizeExftell, _ftelli64Unfortunately you need to use
#ifs to compile your programs for windows and Linux.