From fc44261dd1304c7dd1f38999a13ef9734c23b69a Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 19 Mar 2018 22:57:34 -0500 Subject: FS: Support the file Append open mode. --- src/core/file_sys/disk_filesystem.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/disk_filesystem.cpp') diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index 22b17ba04..9d456e0bf 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -17,10 +17,30 @@ std::string Disk_FileSystem::GetName() const { ResultVal> Disk_FileSystem::OpenFile(const std::string& path, Mode mode) const { - ASSERT_MSG(mode == Mode::Read || mode == Mode::Write, "Other file modes are not supported"); + + std::string mode_str = ""; + u32 mode_flags = static_cast(mode); + + // Calculate the correct open mode for the file. + if ((mode_flags & static_cast(Mode::Read)) && + (mode_flags & static_cast(Mode::Write))) { + if (mode_flags & static_cast(Mode::Append)) + mode_str = "a+"; + else + mode_str = "r+"; + } else { + if (mode_flags & static_cast(Mode::Read)) + mode_str = "r"; + else if (mode_flags & static_cast(Mode::Append)) + mode_str = "a"; + else if (mode_flags & static_cast(Mode::Write)) + mode_str = "w"; + } + + mode_str += "b"; std::string full_path = base_directory + path; - auto file = std::make_shared(full_path, mode == Mode::Read ? "rb" : "wb"); + auto file = std::make_shared(full_path, mode_str.c_str()); if (!file->IsOpen()) { return ERROR_PATH_NOT_FOUND; -- cgit v1.2.3