1 /* @(#)fread.c 4.1 (Berkeley) 05/29/84 */ 2 #include <stdio.h> 3 4 fread(ptr, size, count, iop) 5 register char *ptr; 6 unsigned size, count; 7 register FILE *iop; 8 { 9 register int s; 10 11 s = size * count; 12 while (s > 0) { 13 if (iop->_cnt < s) { 14 if (iop->_cnt > 0) { 15 bcopy(iop->_ptr, ptr, iop->_cnt); 16 ptr += iop->_cnt; 17 s -= iop->_cnt; 18 } 19 /* 20 * filbuf clobbers _cnt & _ptr, 21 * so don't waste time setting them. 22 */ 23 if ((*ptr++ = _filbuf(iop)) == EOF) 24 break; 25 s--; 26 } 27 if (iop->_cnt >= s) { 28 bcopy(iop->_ptr, ptr, s); 29 iop->_ptr += s; 30 iop->_cnt -= s; 31 return (count); 32 } 33 } 34 return (count - ((s + size - 1) / size)); 35 } 36