1 #include <crtdll/stdio.h>
2 #include <crtdll/stdlib.h>
3 #include <crtdll/string.h>
4 #include <crtdll/errno.h>
5 #include <crtdll/internal/file.h>
9 fwrite(const void *p, size_t size, size_t count, FILE *iop)
11 char *ptr = (char *)p;
15 to_write = size * count;
19 while ( to_write > 0 ) {
20 if ( putc(*ptr,iop) == EOF )
28 return count -to_write/size;
34 size_t fwrite(const void *vptr, size_t size, size_t count, FILE *iop)
36 size_t to_write, n_written;
37 char *ptr = (char *)vptr;
39 to_write = size*count;
40 if (!OPEN4WRITING(iop) )
55 if (vptr == NULL || to_write == 0)
59 while(iop->_cnt > 0 && to_write > 0 ) {
64 // if the buffer is dirty it will have to be written now
65 // otherwise the file pointer won't match anymore.
69 n_written = _write(fileno(iop), ptr,to_write);
70 if ( n_written != -1 )
71 to_write -= n_written;
73 // check to see if this will work with in combination with ungetc
76 // the file buffer is empty and there is no read ahead information anymore.
78 iop->_flag &= ~_IOAHEAD;
80 return count - (to_write/size);