#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE
...
off64_t st_size;
...
st_size = (off64_t)lseek64(fd, (off64_t)0, SEEK_END);
fprintf(stderr, "QQQ st_size=%llx %lld\n", st_size, st_size);
然后strace:
$ strace -e _llseek ./the_program
_llseek(3, 0, [20974464000], SEEK_END) = 0
QQQ st_size=ffffffffe22cec00 -500372480
- 20974464000 == 0x4E22CEC00 - 好
- -500372480 == 0xffffffffe22cec00 - 坏
它更改为(off64_t)lseek64(fd, 0, SEEK_END);
错误地调用 _llseek:
_llseek(3, 8589934592, [8589934592], SEEK_SET) = 0
st_size=0 0
我还应该做些什么来确保它正确获得大小,而不切断主要的 dword?