summaryrefslogtreecommitdiff
path: root/Source/Core/Common/IOFile.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-01-05 04:06:35 +0100
committerGitHub <noreply@github.com>2023-01-05 04:06:35 +0100
commit7b04a6b958d74bbe1c3b1dea62163361a707ef0a (patch)
treee2cf0771e685c09fce3b2f7224b17cd355d221bb /Source/Core/Common/IOFile.cpp
parentb6b46d8af3f410db819592b699b4922871238b28 (diff)
parent481ddd1308bf84544c91b62c7a41ec7f9c9f7178 (diff)
Merge pull request #11089 from sepalani/pcap-share
NetworkCaptureLogger: Allow PCAP shared read access on Windows
Diffstat (limited to 'Source/Core/Common/IOFile.cpp')
-rw-r--r--Source/Core/Common/IOFile.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/Source/Core/Common/IOFile.cpp b/Source/Core/Common/IOFile.cpp
index 374c56ac6f..cf7762ea68 100644
--- a/Source/Core/Common/IOFile.cpp
+++ b/Source/Core/Common/IOFile.cpp
@@ -35,9 +35,10 @@ IOFile::IOFile(std::FILE* file) : m_file(file), m_good(true)
{
}
-IOFile::IOFile(const std::string& filename, const char openmode[]) : m_file(nullptr), m_good(true)
+IOFile::IOFile(const std::string& filename, const char openmode[], SharedAccess sh)
+ : m_file(nullptr), m_good(true)
{
- Open(filename, openmode);
+ Open(filename, openmode, sh);
}
IOFile::~IOFile()
@@ -62,12 +63,21 @@ void IOFile::Swap(IOFile& other) noexcept
std::swap(m_good, other.m_good);
}
-bool IOFile::Open(const std::string& filename, const char openmode[])
+bool IOFile::Open(const std::string& filename, const char openmode[],
+ [[maybe_unused]] SharedAccess sh)
{
Close();
#ifdef _WIN32
- m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
+ if (sh == SharedAccess::Default)
+ {
+ m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
+ }
+ else if (sh == SharedAccess::Read)
+ {
+ m_file = _tfsopen(UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str(), SH_DENYWR);
+ m_good = m_file != nullptr;
+ }
#else
#ifdef ANDROID
if (IsPathAndroidContent(filename))