fix "printf("%4.1f\n", (double)0.0);"
[unix-history] / usr / src / lib / libc / stdio / fread.c
CommitLineData
586c39b1
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)fread.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
586c39b1 10
637f6ac3
MK
11#include <stdio.h>
12
13fread(ptr, size, count, iop)
14 register char *ptr;
15 unsigned size, count;
16 register FILE *iop;
17{
18 register int s;
0bc83587 19 int c;
637f6ac3
MK
20
21 s = size * count;
22 while (s > 0) {
23 if (iop->_cnt < s) {
24 if (iop->_cnt > 0) {
25 bcopy(iop->_ptr, ptr, iop->_cnt);
26 ptr += iop->_cnt;
27 s -= iop->_cnt;
28 }
29 /*
30 * filbuf clobbers _cnt & _ptr,
31 * so don't waste time setting them.
32 */
0bc83587 33 if ((c = _filbuf(iop)) == EOF)
637f6ac3 34 break;
0bc83587 35 *ptr++ = c;
637f6ac3
MK
36 s--;
37 }
38 if (iop->_cnt >= s) {
39 bcopy(iop->_ptr, ptr, s);
40 iop->_ptr += s;
41 iop->_cnt -= s;
42 return (count);
43 }
44 }
a2dc047f 45 return (size != 0 ? count - ((s + size - 1) / size) : 0);
637f6ac3 46}