summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2022-01-29 11:59:58 +0100
committerGitHub <noreply@github.com>2022-01-29 11:59:58 +0100
commitaf5678ea758d493c419ca53c56a0ce4f8fa0ca0f (patch)
tree6e76a1fee0e79d593d95c9680d2353f9033b0ac6 /Source/Core/Common
parentfbe7cf675cf412af12d2f750c6162f6e4151c52c (diff)
parenta336c4386c154746ef2ea732b13872f5293666be (diff)
Merge pull request #10403 from AdmiralCurtiss/iofile-seek
Minor IOFile cleanup.
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/IOFile.cpp24
-rw-r--r--Source/Core/Common/IOFile.h11
-rw-r--r--Source/Core/Common/LinearDiskCache.h4
3 files changed, 31 insertions, 8 deletions
diff --git a/Source/Core/Common/IOFile.cpp b/Source/Core/Common/IOFile.cpp
index 1378906357..374c56ac6f 100644
--- a/Source/Core/Common/IOFile.cpp
+++ b/Source/Core/Common/IOFile.cpp
@@ -94,7 +94,7 @@ bool IOFile::Close()
void IOFile::SetHandle(std::FILE* file)
{
Close();
- Clear();
+ ClearError();
m_file = file;
}
@@ -106,9 +106,25 @@ u64 IOFile::GetSize() const
return 0;
}
-bool IOFile::Seek(s64 off, int origin)
-{
- if (!IsOpen() || 0 != fseeko(m_file, off, origin))
+bool IOFile::Seek(s64 offset, SeekOrigin origin)
+{
+ int fseek_origin;
+ switch (origin)
+ {
+ case SeekOrigin::Begin:
+ fseek_origin = SEEK_SET;
+ break;
+ case SeekOrigin::Current:
+ fseek_origin = SEEK_CUR;
+ break;
+ case SeekOrigin::End:
+ fseek_origin = SEEK_END;
+ break;
+ default:
+ return false;
+ }
+
+ if (!IsOpen() || 0 != fseeko(m_file, offset, fseek_origin))
m_good = false;
return m_good;
diff --git a/Source/Core/Common/IOFile.h b/Source/Core/Common/IOFile.h
index 873c4c2af5..0c14fad838 100644
--- a/Source/Core/Common/IOFile.h
+++ b/Source/Core/Common/IOFile.h
@@ -13,6 +13,13 @@
namespace File
{
+enum class SeekOrigin
+{
+ Begin,
+ Current,
+ End,
+};
+
// simple wrapper for cstdlib file functions to
// hopefully will make error checking easier
// and make forgetting an fclose() harder
@@ -89,14 +96,14 @@ public:
std::FILE* GetHandle() { return m_file; }
void SetHandle(std::FILE* file);
- bool Seek(s64 off, int origin);
+ bool Seek(s64 offset, SeekOrigin origin);
u64 Tell() const;
u64 GetSize() const;
bool Resize(u64 size);
bool Flush();
// clear error state
- void Clear()
+ void ClearError()
{
m_good = true;
std::clearerr(m_file);
diff --git a/Source/Core/Common/LinearDiskCache.h b/Source/Core/Common/LinearDiskCache.h
index 78982109b9..46ebde56fa 100644
--- a/Source/Core/Common/LinearDiskCache.h
+++ b/Source/Core/Common/LinearDiskCache.h
@@ -100,8 +100,8 @@ public:
m_num_entries++;
}
- m_file.Clear();
- m_file.Seek(last_valid_value_start, SEEK_SET);
+ m_file.ClearError();
+ m_file.Seek(last_valid_value_start, File::SeekOrigin::Begin);
return m_num_entries;
}