Martin Storsjo : msvcrt: Fix reading BOM-less files opened with ccs=unicode.

Alexandre Julliard julliard at winehq.org
Wed Jan 27 15:35:04 CST 2021


Module: wine
Branch: master
Commit: fb0fa9aacf0d58b3fd5f26255858a744b29ee000
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fb0fa9aacf0d58b3fd5f26255858a744b29ee000

Author: Martin Storsjo <martin at martin.st>
Date:   Wed Jan 27 19:07:26 2021 +0100

msvcrt: Fix reading BOM-less files opened with ccs=unicode.

This fixes a regression in running MSVC 2010 in wine, when reading
.def files (regressed in b0ab1b76029eaface724a28483fe8b0ea36029dc).

Signed-off-by: Martin Storsjo <martin at martin.st>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/file.c       |  6 ++++--
 dlls/msvcrt/tests/file.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index ba534568119..73e1a82476f 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -2329,6 +2329,7 @@ int CDECL _wsopen_dispatch( const wchar_t* path, int oflags, int shflags, int pm
                   msvcrt_set_errno(GetLastError());
                   return *_errno();
               }
+              oflags |= _O_U16TEXT;
           }
       }
       else if (access & GENERIC_READ)
@@ -2346,8 +2347,9 @@ int CDECL _wsopen_dispatch( const wchar_t* path, int oflags, int shflags, int pm
       return *_errno();
 
   if (oflags & _O_WTEXT)
-      get_ioinfo_nolock(*fd)->exflag |= EF_UTF16|EF_UNK_UNICODE;
-  else if (oflags & _O_U16TEXT)
+      get_ioinfo_nolock(*fd)->exflag |= EF_UNK_UNICODE;
+
+  if (oflags & _O_U16TEXT)
       get_ioinfo_nolock(*fd)->exflag |= EF_UTF16;
   else if (oflags & _O_U8TEXT)
       get_ioinfo_nolock(*fd)->exflag |= EF_UTF8;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index ecf99e38b0e..0cf8bad124f 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -1039,6 +1039,40 @@ static void test_fgetwc_unicode(void)
     ch = fgetwc(tempfh);
     ok(ch == WEOF, "got %04hx, expected WEOF (unicode)\n", ch);
     fclose(tempfh);
+
+    tempfh = fopen(tempfile, "wb");
+    ok(tempfh != NULL, "can't open tempfile\n");
+    ret = WideCharToMultiByte(CP_UTF8, 0, wchar_text + 1, ARRAY_SIZE(wchar_text) - 1,
+                              utf8_text, sizeof(utf8_text), NULL, NULL);
+    ok(ret > 0, "utf-8 conversion failed\n");
+    utf8_text[ret] = 0;
+    fwrite(utf8_text, sizeof(char), ret, tempfh);
+    fclose(tempfh);
+
+    tempfh = fopen(tempfile, "rt, ccs=UTF-8");
+    ok(tempfh != NULL, "can't open tempfile\n");
+    for (i = 1; i < ARRAY_SIZE(wchar_text); i++)
+    {
+        ch = fgetwc(tempfh);
+        ok(ch == wchar_text[i],
+           "got %04hx, expected %04x (utf8[%d])\n", ch, wchar_text[i], i-1);
+    }
+    ch = fgetwc(tempfh);
+    ok(ch == WEOF, "got %04hx, expected WEOF (utf8)\n", ch);
+    fclose(tempfh);
+
+    tempfh = fopen(tempfile, "rt, ccs=unicode");
+    ok(tempfh != NULL, "can't open tempfile\n");
+    for (i = 0; utf8_text[i]; i++)
+    {
+        ch = fgetwc(tempfh);
+        ok(ch == (unsigned char) utf8_text[i],
+           "got %04hx, expected %04x (unicode[%d])\n", ch, (unsigned char)utf8_text[i], i);
+    }
+    ch = fgetwc(tempfh);
+    ok(ch == WEOF, "got %04hx, expected WEOF (unicode)\n", ch);
+    fclose(tempfh);
+
     unlink(temppath);
 }
 




More information about the wine-cvs mailing list