From 54467c18b1038f4d82abd4c4a4627c920b6eb0d8 Mon Sep 17 00:00:00 2001 From: R2DLiu Date: Tue, 30 Jun 2020 21:52:44 -0400 Subject: [PATCH] File IO Functions --- Source/Core/Common/File.cpp | 19 +++++++++++++++++++ Source/Core/Common/File.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/Source/Core/Common/File.cpp b/Source/Core/Common/File.cpp index 9dfcdbd7d8..6d86841733 100644 --- a/Source/Core/Common/File.cpp +++ b/Source/Core/Common/File.cpp @@ -34,6 +34,12 @@ IOFile::IOFile(const std::string& filename, const char openmode[]) : m_file(null Open(filename, openmode); } +IOFile::IOFile(const std::string& filename, const char openmode[], int shflag) + : m_file(nullptr), m_good(true) +{ + OpenShared(filename, openmode, shflag); +} + IOFile::~IOFile() { Close(); @@ -69,6 +75,19 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) return m_good; } +bool IOFile::OpenShared(const std::string& filename, const char openmode[], int shflag) +{ + Close(); +#ifdef _WIN32 + m_file = _fsopen(filename.c_str(), openmode, shflag); +#else + m_file = fopen(filename.c_str(), openmode); +#endif + + m_good = IsOpen(); + return m_good; +} + bool IOFile::Close() { if (!IsOpen() || 0 != std::fclose(m_file)) diff --git a/Source/Core/Common/File.h b/Source/Core/Common/File.h index 01b59af257..b38dbd75f8 100644 --- a/Source/Core/Common/File.h +++ b/Source/Core/Common/File.h @@ -21,6 +21,7 @@ public: IOFile(); IOFile(std::FILE* file); IOFile(const std::string& filename, const char openmode[]); + IOFile(const std::string& filename, const char openmode[], int shflag); ~IOFile(); @@ -33,6 +34,9 @@ public: void Swap(IOFile& other) noexcept; bool Open(const std::string& filename, const char openmode[]); + + bool OpenShared(const std::string& filename, const char openmode[], int shflag); + bool Close(); template