From 4e5916fa6fe850990208a9f5c773b0cc43392b17 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 9 Jan 2025 13:12:43 -0800 Subject: [PATCH] CRT/IO: Fixes sharing rules when writing is used Fixes trace file opening since it needs to share with other users opening the file for writing. --- Source/Windows/Common/CRT/IO.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Windows/Common/CRT/IO.cpp b/Source/Windows/Common/CRT/IO.cpp index dd2cb0af03..8afdec9357 100644 --- a/Source/Windows/Common/CRT/IO.cpp +++ b/Source/Windows/Common/CRT/IO.cpp @@ -126,7 +126,13 @@ DLLEXPORT_FUNC(int, _wopen, (const wchar_t* Filename, int OpenFlag, ...)) { Attrs = FILE_ATTRIBUTE_READONLY; } } - HANDLE Handle = CreateFileW(Filename, OpenFlagToAccess(OpenFlag), FILE_SHARE_READ, nullptr, OpenFlagToCreation(OpenFlag), Attrs, nullptr); + auto access = OpenFlagToAccess(OpenFlag); + ULONG sharing = FILE_SHARE_READ; + if (access == GENERIC_WRITE) { + sharing |= FILE_SHARE_WRITE; + } + + HANDLE Handle = CreateFileW(Filename, access, sharing, nullptr, OpenFlagToCreation(OpenFlag), Attrs, nullptr); if (Handle != INVALID_HANDLE_VALUE) { return AllocateFile(std::make_unique(Handle, -1, OpenFlag & _O_APPEND)); }