1
#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?

4

1 回答 1

5

确保您在定义_FILE_OFFSET_BITS_LARGEFILE64_SOURCE 之前包含 sys/types.h 和 unistd.h。最好在编译器的命令行中。

于 2011-01-23T03:49:41.943 回答