IOFile: removes seek limit checks when file is writable

This commit is contained in:
Vinicius Rangel 2024-11-04 02:30:21 -03:00
parent 57a3c0132d
commit 8ea166ea2f
No known key found for this signature in database
GPG Key ID: A5B154D904B761D9
2 changed files with 14 additions and 10 deletions

View File

@ -377,16 +377,18 @@ bool IOFile::Seek(s64 offset, SeekOrigin origin) const {
return false; return false;
} }
u64 size = GetSize(); if (False(file_access_mode & (FileAccessMode::Write | FileAccessMode::Append))) {
if (origin == SeekOrigin::CurrentPosition && Tell() + offset > size) { u64 size = GetSize();
LOG_ERROR(Common_Filesystem, "Seeking past the end of the file"); if (origin == SeekOrigin::CurrentPosition && Tell() + offset > size) {
return false; LOG_ERROR(Common_Filesystem, "Seeking past the end of the file");
} else if (origin == SeekOrigin::SetOrigin && (u64)offset > size) { return false;
LOG_ERROR(Common_Filesystem, "Seeking past the end of the file"); } else if (origin == SeekOrigin::SetOrigin && (u64)offset > size) {
return false; LOG_ERROR(Common_Filesystem, "Seeking past the end of the file");
} else if (origin == SeekOrigin::End && offset > 0) { return false;
LOG_ERROR(Common_Filesystem, "Seeking past the end of the file"); } else if (origin == SeekOrigin::End && offset > 0) {
return false; LOG_ERROR(Common_Filesystem, "Seeking past the end of the file");
return false;
}
} }
errno = 0; errno = 0;

View File

@ -10,6 +10,7 @@
#include "common/concepts.h" #include "common/concepts.h"
#include "common/types.h" #include "common/types.h"
#include "enum.h"
namespace Common::FS { namespace Common::FS {
@ -42,6 +43,7 @@ enum class FileAccessMode {
*/ */
ReadAppend = Read | Append, ReadAppend = Read | Append,
}; };
DECLARE_ENUM_FLAG_OPERATORS(FileAccessMode);
enum class FileType { enum class FileType {
BinaryFile, BinaryFile,