1: #include <stdio.h> 2: 3: char *malloc(); 4: 5: _filbuf(iop) 6: register FILE *iop; 7: { 8: static char smallbuf[_NFILE]; 9: 10: if (iop->_flag & _IORW) 11: iop->_flag |= _IOREAD; 12: 13: if ((iop->_flag & _IOREAD) == 0 || 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: #ifdef UCB_LINEBUF 28: if (iop == stdin && (stdout->_flag&_IOLBF)) 29: fflush(stdout); 30: #endif UCB_LINEBUF 31: iop->_cnt = read(fileno(iop), iop->_base, iop->_flag&_IONBF?1:BUFSIZ); 32: iop->_ptr = iop->_base; 33: if (--iop->_cnt < 0) { 34: if (iop->_cnt == -1) { 35: iop->_flag |= _IOEOF; 36: if (iop->_flag & _IORW) 37: iop->_flag &= ~_IOREAD; 38: } else 39: iop->_flag |= _IOERR; 40: iop->_cnt = 0; 41: return(EOF); 42: } 43: return(*iop->_ptr++ & 0377); 44: }