Skip to content

Commit

Permalink
CRT/IO: Fixes sharing rules when writing is used
Browse files Browse the repository at this point in the history
Fixes trace file opening since it needs to share with other users
opening the file for writing.
  • Loading branch information
Sonicadvance1 committed Jan 9, 2025
1 parent aea08f4 commit 4e5916f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/Windows/Common/CRT/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FILE>(Handle, -1, OpenFlag & _O_APPEND));
}
Expand Down

0 comments on commit 4e5916f

Please sign in to comment.