off_t without -D_FILE_OFFSET_BITS=64 on a file > 2GB

血红的双手。 提交于 2019-12-03 17:02:27
  1. stat() will fail, and errno set to EOVERFLOW in that case. Here's what the linux man page says

    EOVERFLOW  stat()) path refers to a file whose size cannot be
    represented in the type off_t.  This can occur when an application
    

    compiled on a 32-bit platform without -D_FILE_OFFSET_BITS=64 calls stat() on a file whose size exceeds (2<<31)-1 bits.

  2. If you compile with -D_FILE_OFFSET_BITS=64 , you don't need to use off64_t though. You can just continue to use off_t , it'll become 64 bit, and all the functions dealing with files and file sizes will become 64 bit aware.

Never use off64_t explicitly. Always build your programs with 64 bit file offsets on systems where it's necessary to explicitly specify this. Failure to do so is a major bug which your users will end up hating. No idea why it's not default on modern systems...

It oughtn't segfault, but the size of the file won't be reported correctly.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!