Filesystem errors and Base Array Layers (#280)

* Filesystem errors and Base Array Layers

* Fixed build for POSIX

* forgot 1 file
This commit is contained in:
Vladislav Mikhalin 2024-07-11 14:37:21 +03:00 committed by GitHub
parent 59be090c83
commit 989f88837d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 26 deletions

View file

@ -167,7 +167,7 @@ IOFile& IOFile::operator=(IOFile&& other) noexcept {
return *this;
}
void IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, FileShareFlag flag) {
int IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, FileShareFlag flag) {
Close();
file_path = path;
@ -175,21 +175,26 @@ void IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, File
file_type = type;
errno = 0;
int result = 0;
#ifdef _WIN32
if (flag != FileShareFlag::ShareNone) {
file = _wfsopen(path.c_str(), AccessModeToWStr(mode, type), ToWindowsFileShareFlag(flag));
result = errno;
} else {
_wfopen_s(&file, path.c_str(), AccessModeToWStr(mode, type));
result = _wfopen_s(&file, path.c_str(), AccessModeToWStr(mode, type));
}
#else
file = std::fopen(path.c_str(), AccessModeToStr(mode, type));
result = errno;
#endif
if (!IsOpen()) {
LOG_ERROR(Common_Filesystem, "Failed to open the file at path={}",
PathToUTF8String(file_path));
}
return result;
}
void IOFile::Close() {

View file

@ -102,9 +102,9 @@ public:
uintptr_t GetFileMapping();
void Open(const std::filesystem::path& path, FileAccessMode mode,
FileType type = FileType::BinaryFile,
FileShareFlag flag = FileShareFlag::ShareReadOnly);
int Open(const std::filesystem::path& path, FileAccessMode mode,
FileType type = FileType::BinaryFile,
FileShareFlag flag = FileShareFlag::ShareReadOnly);
void Close();
bool Flush() const;