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 // carriage return line feed conversion is done in filbuf and flsbuf
14 fread(void *p, size_t size, size_t count, FILE *iop)
16 char *ptr = (char *)p;
19 to_read = size * count;
23 while ( to_read > 0 ) {
33 return count- (to_read/size);
38 size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
40 char *ptr = (char *)vptr;
41 size_t to_read ,n_read;
43 to_read = size * count;
45 if (!OPEN4READING(iop))
51 if (!__validfp (iop) )
56 if (feof (iop) || ferror (iop))
59 if (vptr == NULL || to_read == 0)
63 while(iop->_cnt > 0 && to_read > 0 ) {
68 // if the buffer is dirty it will have to be written now
69 // otherwise the file pointer won't match anymore.
73 // check to see if this will work with in combination with ungetc
75 n_read = _read(fileno(iop), ptr, to_read);
79 // the file buffer is empty and there is no read ahead information anymore.
81 iop->_flag &= ~_IOAHEAD;
83 return count- (to_read/size);