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
11 fread(void *p, size_t size, size_t count, FILE *iop)
13 char *ptr = (char *)p;
16 to_read = size * count;
20 while ( to_read > 0 ) {
30 return count- (to_read/size);
35 size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
37 char *ptr = (char *)vptr;
38 size_t to_read ,n_read;
40 to_read = size * count;
42 if (!OPEN4READING(iop))
48 if (!__validfp (iop) )
53 if (feof (iop) || ferror (iop))
56 if (vptr == NULL || to_read == 0)
60 while(iop->_cnt > 0 && to_read > 0 ) {
65 // if the buffer is dirty it will have to be written now
66 // otherwise the file pointer won't match anymore.
70 // check to see if this will work with in combination with ungetc
72 n_read = _read(fileno(iop), ptr, to_read);
76 // the file buffer is empty and there is no read ahead information anymore.
78 iop->_flag &= ~_IOAHEAD;
80 return count- (to_read/size);