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>
11 size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
13 unsigned char *ptr = (unsigned char *)vptr;
14 size_t to_read ,n_read;
17 to_read = size * count;
19 if (!OPEN4READING(iop))
25 if (!__validfp (iop) )
30 if (feof (iop) || ferror (iop))
33 if (vptr == NULL || to_read == 0)
36 if (iop->_base == NULL)
46 if (iop->_cnt > 0 && to_read > 0)
48 copy = min(iop->_cnt, to_read);
49 memcpy(ptr, iop->_ptr, copy);
61 if (to_read >= iop->_bufsiz)
63 n_read = _read(fileno(iop), ptr, to_read);
71 // the file buffer is empty and there is no read ahead information anymore.
72 iop->_flag &= ~_IOAHEAD;
81 copy = min(iop->_cnt, to_read);
82 memcpy(ptr, iop->_ptr, copy);
89 return count - (to_read/size);