This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Spam?]Re: problem concating (>>) to a large file


Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:

> > 
> > assert (0 == lseek (open("existing", O_WRONLY | O_APPEND), 0, SEEK_CUR));
> 
> Can you give me a pointer?

http://www.opengroup.org/onlinepubs/009695399/functions/open.html
"The file offset used to mark the current position within the file shall be set 
to the beginning of the file."

This is stated prior to any mention of O_APPEND, and O_APPEND does not change 
that statement.  And for O_APPEND|O_RDWR, it is a necessity.

Later, in http://www.opengroup.org/onlinepubs/009695399/functions/write.html:
"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."

so:

int fd = open("existing", O_WRONLY | O_APPEND);
assert (0 == lseek (fd, 0, SEEK_CUR);
if (write (fd, " ", 1) > 0)
  {
    assert (0 != lseek (fd, 0, SEEK_CUR));
    assert (lseek (fd, 0, SEEK_CUR) == lseek (fd, 0, SEEK_END));
  }

-- 
Eric Blake



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]