#include

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
source share
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
source

If others have this problem, and _FILE_OFFSET_BITS 64 before #include "sys/stat.h" has not yet been resolved, just move it in front of everyone else. I did not figure out which headers also depend on this, but he solved the problem.

+2
source

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
source

You can remove this restriction by including the config.h header file in your program. and there is no need to include the whole file, but you can also put one macroC # define _FILE_OFFSET_BITS 64 to remove the restriction.

0
source