How to check if the current write position is at the end of file using low-level POSIX functions? The first idea is to use lseek and fstat:
off_t sk;
struct stat st;
sk = lseek (f, 0, SEEK_CUR);
fstat (f, &st);
return st->st_size == sk;
However does st->st_size reflect the actual size but not the disk file size, i.e. not including kernel buffered data?
Another idea is to use
off_t scur, send;
scur = lseek (f, 0, SEEK_CUR);
send = lseek (f, 0, SEEK_END);
lseek (f, scur, SEEK_START);
return scur == send;
but this doesn't seems to be fast and adequate way.
Also both ways seem to be non-atomic, so if there is another process appending to the file, the size could be changed after checking current offset.