[net.sources] stdio improvement for 4.2

jr@bbncc5.UUCP (John Robinson) (10/29/85)

In debugging a redisplay problem with GNU emacs, I found that the
write() system call will sometimes (apparently due to caught signals)
return before having written all it was asked.  Seems the auto-resume
feature of 4.2 slow-device output is not completed.

At any rate, this causes stdio problems (turns on the error bit in the
file block), and makes for a bizarre-looking screen.  I modified
flsbuf.c to cause stdio to restart the failed write(), and now all
seems to work fine.

This is the RCS line from the file I used:

/* @(#)flsbuf.c	4.6 (Berkeley) 6/30/83 */

Here are the changes.  The first is to _flsbuf() and the second to
fflush().  The latter is really the one that emacs seems to need:

70,72c70,77
< 	if (rn != n) {
< 		iop->_flag |= _IOERR;
< 		return(EOF);
---
> 	for (;rn != n;) {
> 		/* If write sent nothing or failed, give up */
> 		if (n <= 0) {
> 			iop->_flag |= _IOERR;
> 			return(EOF);
> 		}
> 		base += n; rn -= n;
> 		n = write(fileno(iop), base, rn);
81a87
>   register int wn;
87,89c93,102
< 	if (write(fileno(iop), base, n) != n) {
< 	    iop->_flag |= _IOERR;
< 	    return(EOF);
---
> 	wn = write(fileno(iop), base, n);
> 	/* This retries the write until it decides it's a lost cause */
> 	for (;wn != n;) {
> 	    if (wn <= 0) {
> 		iop->_flag |= _IOERR;
> 		return(EOF);
> 	      }
> 	    base += wn;
> 	    n -= wn;
> 	    wn = write(fileno(iop), base, n);