> > On working systems write()
> > will always return the number of bytes written, if that number is
> > positive.
> While this sounds useful, it appears to be contrary to TFM, which on
> this Sys/VR4 system (like most others I've seen) states in write(2):
[ ... ]
> There is no room here for a non-negative byte count being returned
> when errno is set to EINTR.
That's correct. We weren't talking about any such behavior. If the
number of bytes written is positive then write() has, by definition,
succeeded, and in that case if the kernel returns -1 or sets errno then
it is misdesigned. There are no two ways about this: a working operating
system simply does not throw I/O away! (This is a lesser sin when it's a
human generating the I/O---for instance, when the OS flushes the
keyboard buffer---but still a sin.)
Some people seem to believe that write() *must* return -1/EINTR if the
I/O was interrupted---I've even seen code which assumes this instead of
handling signals properly. But that's the wrong way around. If write()
returns -1 then, on a working system, you can be sure that no bytes were
written successfully; if errno shows up as EINTR you can then conclude
that write() failed because of a signal rather than an I/O error. The
converse statement is false. There are cases, on working systems, when
write() will be interrupted by a signal but will return a positive
number. That's how it should be, if some bytes were written before the
signal. Again: a working system simply does not throw I/O away!
---Dan