1: #include <stdio.h> 2: 3: char *malloc(); 4: 5: 6: int 7: _filbuf(iop) 8: register FILE *iop; 9: { 10: static char smallbuf[_NFILE]; 11: 12: if (iop->_flag & _IORW) 13: iop->_flag |= _IOREAD; 14: 15: if ((iop->_flag & _IOREAD) == 0 || iop->_flag & _IOSTRG) 16: return(EOF); 17: 18: tryagain: 19: if (iop->_base == NULL) { 20: if (iop->_flag & _IONBF) { 21: iop->_base = &smallbuf[fileno(iop)]; 22: goto tryagain; 23: } 24: if ((iop->_base = malloc(BUFSIZ)) == NULL) { 25: iop->_flag |= _IONBF; 26: goto tryagain; 27: } 28: iop->_flag |= _IOMYBUF; 29: } 30: iop->_ptr = iop->_base; 31: iop->_cnt = read(fileno(iop), iop->_ptr, iop->_flag&_IONBF?1:BUFSIZ); 32: if (--iop->_cnt < 0) { 33: if (iop->_cnt == -1) { 34: iop->_flag |= _IOEOF; 35: if (iop->_flag & _IORW) 36: iop->_flag &= ~_IOREAD; 37: } else 38: iop->_flag |= _IOERR; 39: iop->_cnt = 0; 40: return(EOF); 41: } 42: return(*iop->_ptr++ & 0377); 43: }