Write calls which do partial writes

John E Van Deusen III jiii at visdc.UUCP
Thu May 4 04:33:21 AEST 1989


In article <103 at matrix.UUCP> neeraj at matrix.UUCP (neeraj sangal) writes:
>        n = write(fd, buf, len);
>
>    As documented in write(2), n is the number of bytes written if the
> call  is successful; n is -1 otherwise.

I have recently purchased a book called C LANGUAGE INTERFACES that is
part of the Prentice Hall, AT&T series.  It has a wealth of information
about this sort of thing that was completely absent in the documentation
that I previously used; the AT&T UNIX SYSTEM V PROGRAMMER'S REFERENCE
MANUAL, also published by Prentice Hall.

When writing to pipes and FIFO's there are only so many bytes that will
fit at any given time (PIPE_BUF).  If more than PIPE_BUF bytes are to be
written, and O_NDELAY is clear, the bytes are written piecemeal until
the write is satisfied.  Because this process is not atomic, it is
possible for other processes to interleave output.  If this is a problem
O_NDELAY can be set, and write(2) will return the number of bytes that
could be written contiguously.

If the request is for PIPE_BUF bytes or less, and O_NDELAY is clear, the
process will block until the entire request can be accommodated.  If
O_NDELAY is set, and there is not enough room for the entire write
request, zero is returned.  Write requests of PIPE_BUF bytes or less
are always contiguous.
--
John E Van Deusen III, PO Box 9283, Boise, ID  83707, (208) 343-1865

uunet!visdc!jiii



More information about the Comp.unix.wizards mailing list