|
|
1.1 ! root 1: static char *sccsid = "@(#)filbuf.c 34.1 10/3/80"; ! 2: ! 3: #include <stdio.h> ! 4: char *malloc(); ! 5: ! 6: _filbuf(iop) ! 7: register FILE *iop; ! 8: { ! 9: static char smallbuf[_NFILE]; ! 10: ! 11: if ((iop->_flag&_IOREAD) == 0) ! 12: return(EOF); ! 13: if (iop->_flag&_IOSTRG) ! 14: return(EOF); ! 15: tryagain: ! 16: if (iop->_base==NULL) { ! 17: if (iop->_flag&_IONBF) { ! 18: iop->_base = &smallbuf[fileno(iop)]; ! 19: goto tryagain; ! 20: } ! 21: if ((iop->_base = malloc(BUFSIZ)) == NULL) { ! 22: iop->_flag |= _IONBF; ! 23: goto tryagain; ! 24: } ! 25: iop->_flag |= _IOMYBUF; ! 26: } ! 27: iop->_ptr = iop->_base; ! 28: if (iop == stdin && (stdout->_flag&_IOLBF)) ! 29: fflush(stdout); ! 30: iop->_cnt = read(fileno(iop), iop->_ptr, iop->_flag&_IONBF?1:BUFSIZ); ! 31: iop->_ptr = iop->_base; ! 32: if (--iop->_cnt < 0) { ! 33: if (iop->_cnt == -1) ! 34: iop->_flag |= _IOEOF; ! 35: else ! 36: iop->_flag |= _IOERR; ! 37: iop->_cnt = 0; ! 38: return(-1); ! 39: } ! 40: return(*iop->_ptr++&0377); ! 41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.