1 /* @(#)setbuffer.c 4.5 (Berkeley) 02/13/85 */ 2 #include <stdio.h> 3 4 setbuffer(iop, buf, size) 5 register FILE *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 FILE *iop; 27 { 28 char *buf; 29 extern char *malloc(); 30 31 fflush(iop); 32 setbuffer(iop, NULL, 0); 33 buf = malloc(BUFSIZ); 34 if (buf != NULL) { 35 setbuffer(iop, buf, BUFSIZ); 36 iop->_flag |= _IOLBF|_IOMYBUF; 37 } 38 } 39