msvcrt: Implement bufsiz block flushing behavior.

This commit is contained in:
Grazvydas Ignotas 2014-06-18 13:55:53 +03:00 committed by Alexandre Julliard
parent c6a160691a
commit ad968be779
2 changed files with 13 additions and 1 deletions

View File

@ -3720,6 +3720,18 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si
}
written += wrcnt;
wrcnt = 0;
} else if(file->_bufsiz && wrcnt >= file->_bufsiz) {
MSVCRT_size_t pcnt=(wrcnt / file->_bufsiz) * file->_bufsiz;
if(msvcrt_flush_buffer(file) == MSVCRT_EOF)
break;
if(MSVCRT__write(file->_file, ptr, pcnt) <= 0) {
file->_flag |= MSVCRT__IOERR;
break;
}
written += pcnt;
wrcnt -= pcnt;
ptr = (const char*)ptr + pcnt;
} else {
if(MSVCRT__flsbuf(*(const char*)ptr, file) == MSVCRT_EOF)
break;

View File

@ -2243,7 +2243,7 @@ static void test_write_flush_size(FILE *file, int bufsize)
fseek(file, 0, SEEK_SET);
ok(fread(inbuffer, 1, bufsize, file) == bufsize, "read failed\n");
if (size == bufsize)
todo_wine ok(memcmp(outbuffer, inbuffer, bufsize) == 0, "missing flush by %d byte write\n", size);
ok(memcmp(outbuffer, inbuffer, bufsize) == 0, "missing flush by %d byte write\n", size);
else
ok(memcmp(outbuffer, inbuffer, bufsize) != 0, "unexpected flush by %d byte write\n", size);
}