Write calls which do partial writes

Doug Gwyn gwyn at smoke.BRL.MIL
Wed May 3 21:19:34 AEST 1989


In article <103 at matrix.UUCP> neeraj at matrix.UUCP (neeraj sangal) writes:
>        n = write(fd, buf, len);
>    1. Can n be less than len if fd is NOT set to non-blocking?

Certainly; if only some but not all bytes were transferred,
for example due to the system call being interrupted by a signal,
then the best thing for write() to report is the number of bytes
successfully transferred.  (I forget whether IEEE 1003.1 ended up
permitting this or not; it was hotly debated.)  Robust stdio
implementations have to loop on the write() call until all bytes
are transferred or an error occurs.

>Will the underlying protocol complete select the moment a single
>byte can be transferred...?

Obviously it should.

The details depend on the exact implementation and are complicated
by things like the guaranteed pipe atomic write size, etc.



More information about the Comp.unix.wizards mailing list