1 #include <msvcrt/stdio.h>
2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/string.h>
4 #include <msvcrt/errno.h>
5 #include <msvcrt/internal/file.h>
8 size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
10 unsigned char *ptr = (unsigned char *)vptr;
11 size_t to_read ,n_read;
14 to_read = size * count;
16 if (!OPEN4READING(iop))
22 if (!__validfp (iop) )
27 if (feof (iop) || ferror (iop))
30 if (vptr == NULL || to_read == 0)
33 if (iop->_base == NULL)
43 if (iop->_cnt > 0 && to_read > 0)
45 copy = min(iop->_cnt, to_read);
46 memcpy(ptr, iop->_ptr, copy);
58 if (to_read >= iop->_bufsiz)
60 n_read = _read(fileno(iop), ptr, to_read);
68 // the file buffer is empty and there is no read ahead information anymore.
69 iop->_flag &= ~_IOAHEAD;
78 copy = min(iop->_cnt, to_read);
79 memcpy(ptr, iop->_ptr, copy);
86 return count - (to_read/size);