[2/4] msvcrt: Move write flag setting code for reuse. (try 2)

Grazvydas Ignotas notasas at gmail.com
Thu Jun 12 18:27:05 CDT 2014


---
 dlls/msvcrt/file.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 7ebf6d2..7dee5d6 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -3639,6 +3639,17 @@ MSVCRT_wchar_t * CDECL MSVCRT_fgetws(MSVCRT_wchar_t *s, int size, MSVCRT_FILE* f
   return buf_start;
 }
 
+static inline int msvcrt_set_write_direction(MSVCRT_FILE* file)
+{
+    if(!(file->_flag & MSVCRT__IOWRT)) {
+        if(file->_flag & MSVCRT__IORW)
+            file->_flag |= MSVCRT__IOWRT;
+        else
+            return MSVCRT_EOF;
+    }
+    return 0;
+}
+
 /*********************************************************************
  *		_flsbuf (MSVCRT.@)
  */
@@ -3648,12 +3659,8 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
     if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) {
         msvcrt_alloc_buffer(file);
     }
-    if(!(file->_flag & MSVCRT__IOWRT)) {
-        if(file->_flag & MSVCRT__IORW)
-            file->_flag |= MSVCRT__IOWRT;
-        else
-            return MSVCRT_EOF;
-    }
+    if(msvcrt_set_write_direction(file) != 0)
+        return MSVCRT_EOF;
     if(file->_bufsiz) {
         int res = 0;
 
@@ -3704,12 +3711,8 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si
             wrcnt -= pcnt;
             ptr = (const char*)ptr + pcnt;
         } else if(!file->_bufsiz && (file->_flag & MSVCRT__IONBF)) {
-            if(!(file->_flag & MSVCRT__IOWRT)) {
-                if(file->_flag & MSVCRT__IORW)
-                    file->_flag |= MSVCRT__IOWRT;
-                else
-                    break;
-            }
+            if(msvcrt_set_write_direction(file) != 0)
+                break;
 
             if(MSVCRT__write(file->_file, ptr, wrcnt) <= 0) {
                 file->_flag |= MSVCRT__IOERR;
-- 
1.7.9.5




More information about the wine-patches mailing list