From: Piotr Caban Subject: [PATCH 1/2 v2] msvcrt: Don't write Unicode BOM if file is not empty in _wsopen_dispatch. Message-Id: Date: Thu, 26 Nov 2020 15:26:27 +0100 Signed-off-by: Piotr Caban --- 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 1cf778cca07..b3e0b4abeaa 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2297,9 +2297,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) {