Stat call from <sys / stat.h> with the error "The value is too large for a particular data type"
Given tmp.c:
#include <sys/stat.h> #include <errno.h> #include <stdio.h> int main(int argc, const char *argv[]) { struct stat st; if (stat(argv[1], &st) != 0) { perror("Error calling stat"); } return 0; } I get Error calling stat: Value too large for defined data type when I run the program in a large file (~ 2.5 GB).
+4
4 answers
You need #define _FILE_OFFSET_BITS 64 : either add it before yourself #include <sys/stat.h> or define it in a certain way for your platform, for example, for the gcc see -D option; for Visual Studio go to project properties -> Configuration Properties -> C / C ++ -> Preprocessor -> Preprocessor Definitions
+7
Pay attention to the link. This gives you the opportunity to deal with such a problem.
This is usually done by defining -D_FILE_OFFSET_BITS = 64 or some of these. It depends on the system. After execution and after switching to this new mode, most programs will support large files just fine.
0