1 /* @(#)setbuffer.c 4.3 (Berkeley) 05/15/84 */ 2 #include <stdio.h> 3 4 setbuffer(iop, buf, size) 5 register struct _iobuf *iop; 6 char *buf; 7 int size; 8 { 9 if (iop->_base != NULL && iop->_flag&_IOMYBUF) 10 free(iop->_base); 11 iop->_flag &= ~(_IOMYBUF|_IONBF|_IOLBF); 12 if ((iop->_base = buf) == NULL) { 13 iop->_flag |= _IONBF; 14 iop->_bufsiz = NULL; 15 } else { 16 iop->_ptr = iop->_base; 17 iop->_bufsiz = size; 18 } 19 iop->_cnt = 0; 20 } 21 22 /* 23 * set line buffering for either stdout or stderr 24 */ 25 setlinebuf(iop) 26 register struct _iobuf *iop; 27 { 28 extern char *malloc(); 29 30 fflush(iop); 31 setbuffer(iop, malloc(BUFSIZ), BUFSIZ); 32 iop->_flag |= _IOLBF|_IOMYBUF; 33 } 34