[3/3] msvcrt: Implement 4k block flushing behavior.

Grazvydas Ignotas notasas at gmail.com
Fri May 30 18:00:40 CDT 2014


---
 dlls/msvcrt/file.c       |   17 +++++++++++++++++
 dlls/msvcrt/tests/file.c |    2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 02f99e2..c841033 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -81,6 +81,8 @@ static char utf16_bom[2] = { 0xff, 0xfe };
 #define MSVCRT_MAX_FILES 2048
 #define MSVCRT_FD_BLOCK_SIZE 32
 
+#define MSVCRT_WRITE_BLOCK_SIZE 4096
+
 /* ioinfo structure size is different in msvcrXX.dll's */
 typedef struct {
     HANDLE              handle;
@@ -3716,6 +3718,21 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si
             }
             written += wrcnt;
             wrcnt = 0;
+        } else if(wrcnt >= MSVCRT_WRITE_BLOCK_SIZE) {
+            if(msvcrt_set_write_direction(file) != 0)
+                break;
+
+            if(file->_bufsiz && file->_ptr != file->_base)
+                if(msvcrt_flush_buffer(file) == MSVCRT_EOF)
+                    break;
+
+            if(MSVCRT__write(file->_file, ptr, MSVCRT_WRITE_BLOCK_SIZE) <= 0) {
+                file->_flag |= MSVCRT__IOERR;
+                break;
+            }
+            written += MSVCRT_WRITE_BLOCK_SIZE;
+            wrcnt -= MSVCRT_WRITE_BLOCK_SIZE;
+            ptr = (const char*)ptr + MSVCRT_WRITE_BLOCK_SIZE;
         } else {
             if(MSVCRT__flsbuf(*(const char*)ptr, file) == MSVCRT_EOF)
                 break;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 37e6816..885b66b 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -2244,7 +2244,7 @@ static void test_write_flush(void)
         fseek(file, 0, SEEK_SET);
         ok(fread(inbuffer, 1, sizeof(inbuffer), file) == sizeof(inbuffer), "read failed\n");
         if (size % 4096 == 0)
-          todo_wine ok(memcmp(outbuffer, inbuffer, sizeof(inbuffer)) == 0, "missing flush by %d byte write\n", size);
+          ok(memcmp(outbuffer, inbuffer, sizeof(inbuffer)) == 0, "missing flush by %d byte write\n", size);
         else
           ok(memcmp(outbuffer, inbuffer, sizeof(inbuffer)) != 0, "unexpected flush by %d byte write\n", size);
     }
-- 
1.7.9.5




More information about the wine-patches mailing list