From a4120ca66cc6c0f3a8056c6ea247c15f63c7feff Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:29:16 -0400 Subject: file_util: Don't expose IOFile internals through the API --- src/common/file_util.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'src/common/file_util.cpp') diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 9ada09f8a..578c673b9 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -824,13 +824,12 @@ size_t WriteStringToFile(bool text_file, const std::string &str, const char *fil size_t ReadFileToString(bool text_file, const char *filename, std::string &str) { - FileUtil::IOFile file(filename, text_file ? "r" : "rb"); - auto const f = file.GetHandle(); + IOFile file(filename, text_file ? "r" : "rb"); - if (!f) + if (!file) return false; - str.resize(static_cast(GetSize(f))); + str.resize(static_cast(file.GetSize())); return file.ReadArray(&str[0], str.size()); } @@ -880,10 +879,6 @@ IOFile::IOFile() : m_file(nullptr), m_good(true) {} -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) { @@ -935,20 +930,6 @@ bool IOFile::Close() return m_good; } -std::FILE* IOFile::ReleaseHandle() -{ - std::FILE* const ret = m_file; - m_file = nullptr; - return ret; -} - -void IOFile::SetHandle(std::FILE* file) -{ - Close(); - Clear(); - m_file = file; -} - u64 IOFile::GetSize() { if (IsOpen()) -- cgit v1.2.3 From 655623ebb2dd6f3f1451e5b8b92dc755868347c8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:38:01 -0400 Subject: file_util: const qualify IOFile's Tell and GetSize functions --- src/common/file_util.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/common/file_util.cpp') diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 578c673b9..7d96d04d9 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -930,12 +930,12 @@ bool IOFile::Close() return m_good; } -u64 IOFile::GetSize() +u64 IOFile::GetSize() const { if (IsOpen()) return FileUtil::GetSize(m_file); - else - return 0; + + return 0; } bool IOFile::Seek(s64 off, int origin) @@ -946,12 +946,12 @@ bool IOFile::Seek(s64 off, int origin) return m_good; } -u64 IOFile::Tell() +u64 IOFile::Tell() const { if (IsOpen()) return ftello(m_file); - else - return -1; + + return -1; } bool IOFile::Flush() -- cgit v1.2.3 From 5f51622e9de0483519f47c749888fe7d5b120c79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:48:03 -0400 Subject: file_util: In-class initialize data members --- src/common/file_util.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/common/file_util.cpp') diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 7d96d04d9..53700c865 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -876,11 +876,10 @@ void SplitFilename83(const std::string& filename, std::array& short_nam } IOFile::IOFile() - : m_file(nullptr), m_good(true) -{} +{ +} IOFile::IOFile(const std::string& filename, const char openmode[]) - : m_file(nullptr), m_good(true) { Open(filename, openmode); } @@ -891,7 +890,6 @@ IOFile::~IOFile() } IOFile::IOFile(IOFile&& other) - : m_file(nullptr), m_good(true) { Swap(other); } -- cgit v1.2.3