Commit | Line | Data |
---|---|---|
a2dc047f | 1 | /* @(#)fread.c 4.3 (Berkeley) %G% */ |
637f6ac3 MK |
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; | |
0bc83587 | 10 | int c; |
637f6ac3 MK |
11 | |
12 | s = size * count; | |
13 | while (s > 0) { | |
14 | if (iop->_cnt < s) { | |
15 | if (iop->_cnt > 0) { | |
16 | bcopy(iop->_ptr, ptr, iop->_cnt); | |
17 | ptr += iop->_cnt; | |
18 | s -= iop->_cnt; | |
19 | } | |
20 | /* | |
21 | * filbuf clobbers _cnt & _ptr, | |
22 | * so don't waste time setting them. | |
23 | */ | |
0bc83587 | 24 | if ((c = _filbuf(iop)) == EOF) |
637f6ac3 | 25 | break; |
0bc83587 | 26 | *ptr++ = c; |
637f6ac3 MK |
27 | s--; |
28 | } | |
29 | if (iop->_cnt >= s) { | |
30 | bcopy(iop->_ptr, ptr, s); | |
31 | iop->_ptr += s; | |
32 | iop->_cnt -= s; | |
33 | return (count); | |
34 | } | |
35 | } | |
a2dc047f | 36 | return (size != 0 ? count - ((s + size - 1) / size) : 0); |
637f6ac3 | 37 | } |