且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

readdir() 32/64 兼容性问题

更新时间:2023-09-11 23:46:34

为了得到一个带有 GCC 和 Glibc 的 64 位 ino_t,你需要定义 特性 _XOPEN_SOURCE_FILE_OFFSET_BITS=64.

In order to get a 64-bit ino_t with GCC and Glibc, you need to define the features _XOPEN_SOURCE and _FILE_OFFSET_BITS=64.

$ echo '#include <dirent.h>' | gcc -m32 -E -D_XOPEN_SOURCE -D_FILE_OFFSET_BITS=64 - | grep ino
__extension__ typedef unsigned long int __ino_t;
__extension__ typedef __u_quad_t __ino64_t;
typedef __ino64_t ino_t;
    __ino64_t d_ino;

我是从文档阅读和检查预处理器中说这句话的,而不是来自深入的经验或对 inode 编号高于 2^32 的文件系统进行测试,所以我不保证你不会遇到其他问题.

I say this from documentation reading and checking the preprocessor, not from deep experience or testing with a filesystem with inode numbers above 2^32, so I don't guarantee that you won't run into other problems down the line.