【问题标题】:Can't get large file support for stat on CentOS 6在 CentOS 6 上无法获得对 stat 的大文件支持
【发布时间】:2015-01-07 14:24:01
【问题描述】:

我刚刚安装了 vanilla CentOS 6,当我尝试使用 -D_FILE_OFFSET_BITS=64 获得大文件支持时,字段 st_size 仍然只有 32 位

uname -a:

Linux vm01 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

我可以看到这个主机是 64 位的。

我的简单测试程序看 st_size 是否接受大于 32 位的值:

#include <sys/stat.h>

int main(int argc, char *argv[]) {
  struct stat s;

  s.st_size = 1024*1024*1024*1024; // 1 Tbyte
  return 0;
}

编译命令:

gcc -c test.c -D_FILE_OFFSET_BITS=64 -o test

结果:

test.c:在函数“main”中: test.c:7: 警告:左移计数 >= 类型宽度

我不明白为什么 gcc 会抱怨,因为根据我读过的所有文档,stat 应该支持大文件,例如 st_size 的 64 位。

gcc -v

使用内置规范。 目标:x86_64-redhat-linux 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable -shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages= c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0- gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux 线程模型:posix gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

谁能帮我解开这个谜团?

谢谢

【问题讨论】:

    标签: c linux gcc


    【解决方案1】:

    如果你想使用一个大数字,那么你需要告诉编译器你想使用一个大数字。

    s.st_size = 1024ULL * 1024 * 1024 * 1024;
    

    【讨论】:

    • 谢谢,我知道这很容易解决,有时我只见树木不见森林 :-)
    猜你喜欢
    • 1970-01-01
    • 2015-11-04
    • 2013-09-02
    • 2016-08-09
    • 2016-11-27
    • 2011-08-28
    • 1970-01-01
    • 2017-05-27
    • 2015-06-06
    相关资源
    最近更新 更多