don't do 1 byte writes, buffer and flush unbuffered I/O (stderr).
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 5 May 1984 04:52:37 +0000 (20:52 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 5 May 1984 04:52:37 +0000 (20:52 -0800)
SCCS-vsn: lib/libc/stdio/fprintf.c 4.2

usr/src/lib/libc/stdio/fprintf.c

index 4d2e1af..54125e2 100644 (file)
@@ -1,10 +1,22 @@
-/* @(#)fprintf.c       4.1 (Berkeley) %G% */
+/* @(#)fprintf.c       4.2 (Berkeley) %G% */
 #include       <stdio.h>
 
 fprintf(iop, fmt, args)
 FILE *iop;
 char *fmt;
 {
 #include       <stdio.h>
 
 fprintf(iop, fmt, args)
 FILE *iop;
 char *fmt;
 {
-       _doprnt(fmt, &args, iop);
+       char localbuf[BUFSIZ];
+
+       if (iop->_flag & _IONBF) {
+               iop->_flag &= ~_IONBF;
+               iop->_ptr = iop->_base = localbuf;
+               iop->_bufsiz = BUFSIZ;
+               _doprnt(fmt, &args, iop);
+               fflush(iop);
+               iop->_flag |= _IONBF;
+               iop->_base = NULL;
+               iop->_bufsiz = NULL;
+       } else
+               _doprnt(fmt, &args, iop);
        return(ferror(iop)? EOF: 0);
 }
        return(ferror(iop)? EOF: 0);
 }