7 size_t fwrite(const void *vptr
, size_t size
, size_t count
, FILE *iop
)
9 size_t to_write
, n_written
;
10 unsigned char *ptr
= (unsigned char *)vptr
;
13 DPRINT("fwrite(%x, %d, %d, %x)\n", vptr
, size
, count
, iop
);
15 to_write
= size
*count
;
16 if (!OPEN4WRITING(iop
))
30 if (vptr
== NULL
|| to_write
== 0)
33 if (iop
->_base
== NULL
&& !(iop
->_flag
&_IONBF
))
35 if (EOF
== _flsbuf(*ptr
++, iop
))
41 if (iop
->_flag
& _IOLBF
)
45 if (EOF
== putc(*ptr
++, iop
))
55 if (iop
->_cnt
> 0 && to_write
> 0)
57 copy
= min(iop
->_cnt
, to_write
);
58 memcpy(iop
->_ptr
, ptr
, copy
);
63 iop
->_flag
|= _IODIRTY
;
68 // if the buffer is dirty it will have to be written now
69 // otherwise the file pointer won't match anymore.
71 if (to_write
>= iop
->_bufsiz
)
75 n_written
= _write(_fileno(iop
), ptr
, to_write
);
81 to_write
-= n_written
;
85 // check to see if this will work with in combination with ungetc
87 // the file buffer is empty and there is no read ahead information anymore.
88 iop
->_flag
&= ~_IOAHEAD
;
92 if (EOF
!= _flsbuf(*ptr
++, iop
))
96 memcpy(iop
->_ptr
, ptr
, to_write
);
97 iop
->_ptr
+= to_write
;
98 iop
->_cnt
-= to_write
;
99 iop
->_flag
|= _IODIRTY
;
107 return count
- (to_write
/size
);