Is it possible when a file is open with
lseek to the top and rewrite the file?
Per the POSIX documentation for
If the O_APPEND flag of the file status flags is set, the file offset shall be set to the end of the file prior to each write and no intervening file modification operation shall occur between changing the file offset and the write operation.
You can use
pwrite() function shall be equivalent to
write(), except that it writes into a given position and does not change the file offset (regardless of whether
O_APPEND is set). The first three arguments to
pwrite() are the same as
write() with the addition of a fourth argument offset for the desired position inside the file. ...
You'd just have to manage the offsets yourself.
pwrite() is broken on Linux:
POSIX requires that opening a file with the
O_APPEND flag should
have no effect on the location at which
pwrite() writes data.
However, on Linux, if a file is opened with
appends data to the end of the file, regardless of the value of
So on Linux there's no way to rewrite a file opened with