Question

#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);

Then strace:

$ strace -e _llseek ./the_program
_llseek(3, 0, [20974464000], SEEK_END)  = 0
QQQ st_size=ffffffffe22cec00 -500372480
  • 20974464000 == 0x4E22CEC00 - good
  • -500372480 == 0xffffffffe22cec00 - bad

It change to (off64_t)lseek64(fd, 0, SEEK_END); it calls _llseek incorrectly:

_llseek(3, 8589934592, [8589934592], SEEK_SET) = 0
st_size=0 0

What more should I do to ensure it gets the size correctly, without chopping off major dword?

Was it helpful?

Solution

Ensure you're defining _FILE_OFFSET_BITS and _LARGEFILE64_SOURCE before including sys/types.h and unistd.h. Preferably, in you compiler's command line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top