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>
12 fwrite(const void *p, size_t size, size_t count, FILE *iop)
14 char *ptr = (char *)p;
18 to_write = size * count;
22 while ( to_write > 0 ) {
23 if ( putc(*ptr,iop) == EOF )
31 return count -to_write/size;
37 size_t fwrite(const void *vptr, size_t size, size_t count, FILE *iop)
39 size_t to_write, n_written;
40 char *ptr = (char *)vptr;
42 to_write = size*count;
43 if (!OPEN4WRITING(iop) )
58 if (vptr == NULL || to_write == 0)
62 while(iop->_cnt > 0 && to_write > 0 ) {
67 // if the buffer is dirty it will have to be written now
68 // otherwise the file pointer won't match anymore.
72 n_written = _write(fileno(iop), ptr,to_write);
73 if ( n_written != -1 )
74 to_write -= n_written;
76 // check to see if this will work with in combination with ungetc
79 // the file buffer is empty and there is no read ahead information anymore.
81 iop->_flag &= ~_IOAHEAD;
83 return count - (to_write/size);