从<sys/stat.h>调用stat会出现"对于已定义的数据类型而言值太大"错误

Ant*_*yko 7 c posix runtime-error system-calls

鉴于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;
}
Run Code Online (Sandbox Code Playgroud)

Error calling stat: Value too large for defined data type当我在大文件(~2.5 Gb)上运行程序时,我得到了.

Ant*_*yko 9

需要#define _FILE_OFFSET_BITS 64:在您之前添加它 #include <sys/stat.h>或以特定于平台的方式定义它,例如,对于gcc,请参阅-D选项; 对于Visual Studio,转到项目属性 - >配置属性 - > C/C++ - >预处理器 - >预处理器定义