Piotr Caban : msvcrt: Don't write Unicode BOM if file is not empty in _wsopen_dispatch.

Alexandre Julliard julliard at winehq.org
Tue Mar 23 15:07:43 CDT 2021


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu Nov 26 15:26:27 2020 +0100

msvcrt: Don't write Unicode BOM if file is not empty in _wsopen_dispatch.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 00a024725e86f3dd3f8bb52849fd2597bbf58d40)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/msvcrt/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 825d442bfa8..d5aff642904 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -2301,9 +2301,14 @@ int CDECL MSVCRT__wsopen_dispatch( const MSVCRT_wchar_t* path, int oflags, int s
 
   if (oflags & (MSVCRT__O_WTEXT|MSVCRT__O_U16TEXT|MSVCRT__O_U8TEXT))
   {
+      LARGE_INTEGER size = {{0}};
+
+      if ((access & GENERIC_WRITE) && (creation==OPEN_EXISTING || creation==OPEN_ALWAYS))
+          GetFileSizeEx(hand, &size);
+
       if ((access & GENERIC_WRITE) && (creation==CREATE_NEW
                   || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING
-                  || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS)))
+                  || ((creation==OPEN_EXISTING || creation==OPEN_ALWAYS) && !size.QuadPart)))
       {
           if (oflags & MSVCRT__O_U8TEXT)
           {




More information about the wine-cvs mailing list