reflum, On Sun, 2013-02-24 at 09:12 +0530, Sachidananda wrote: > > Also, for the record, it's open that seeks to the end. You can open > a > > file with O_APPEND and seek back to the beginning, and write will > not > > seek to the end again. > My observation is, if I open(2) the file with O_APPEND it seeks to > the > end. And I lseek back to the beginning and write(2) to it, write does > seek back to the end and write the data at the end.
From POSIX: > 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. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html) As of my understanding this is to allow race condition free appending to files such as log files so no data is lost. because of the fact that write can return a 'short write' data may be interleaved somehow but no data is lost. (Example of such a case: two processes/threads using the same logfile to log errors. something happens and both write down an error message at the same time. O_APPEND ensures no data is lost here.) Hope that helped! :) -- Philipp. (Rah of PH2)
signature.asc
Description: This is a digitally signed message part
