in reply to open for append

I learned that the POSIX C library guarantees that, when multiple processes are writing to the same file, and all of them have the file opened for appending, data shall not be lost.

I don't think it guarantees that data shall not be lost ... There's still to much going on to guarantee no lost data (you can still get errors such as EFBIG, EINTR, ENOSPC, and EIO).

From the spec a write can be any size:
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.

The only time to worry is if you're writing to a PIPE or FIFO:
Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data from other processes doing writes on the same pipe. Writes of greater than {PIPE_BUF} bytes may have data interleaved, on arbitrary boundaries, with writes by other processes, whether or not the O_NONBLOCK flag of the file status flags is set.

-derby

Replies are listed 'Best First'.
Re^2: open for append
by cmeyer (Pilgrim) on Aug 25, 2005 at 15:46 UTC

    Good point. I'll edit my post to say that the C library guarantees that data shall not be overwritten.

    -Colin.

    WHITEPAGES.COM | INC

      the C library guarantees that data shall not be overwritten
      But it's not the C library either. It's the kernel. The C library doesn't care, and doesn't know that O_APPEND was used. It simply does the write(2) call, and because the open(1) call had O_APPEND, the kernel arranges for write-at-end in an atomic fashion.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.