从 <sys/stat.h> 调用 stat 失败并出现 "Value too large for defined data type"错误

标签 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;
}

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

最佳答案

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

关于从 <sys/stat.h> 调用 stat 失败并出现 "Value too large for defined data type"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13893580/

相关文章:

c - 获取输入数组返回错误结果

c - 为什么第二线程中的暂停(2)不返回?

perl - 为什么 POSIX 与 Win32 一起使用 floor() 抛出警告?

sql - 错误 "<file-name> already exists with <field/value...> (132)"

excel - 运行时错误 5 : Invalid Procedure Call or Argument

c++ - 什么定义了递归函数?

c - 使用 makefile 构建 gtk 项目时找不到“gtk/gtk.h”文件

linux - 如何使用 _FILE_OFFSET_BITS 64 编译的应用程序创建一个小文件(大小 <= 2GB)文件?

c - 正则表达式似乎有误 - 找不到电子邮件

c# - MVC 5 ViewModel 无法像在 MVC 4 中那样工作