From b6967c8a9190efa4e9128850fa723fe3ea3140f7 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 28 Sep 2024 11:14:31 -0500 Subject: Expand directory interface, remove FileStatus for FudStatus. --- source/fud_c_file.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'source/fud_c_file.cpp') diff --git a/source/fud_c_file.cpp b/source/fud_c_file.cpp index cad4c9d..b323847 100644 --- a/source/fud_c_file.cpp +++ b/source/fud_c_file.cpp @@ -38,13 +38,13 @@ CBinaryFile::~CBinaryFile() { close(); } -FileStatus CBinaryFile::open() +FudStatus CBinaryFile::open() { if (!m_filename.valid()) { - return FileStatus::InvalidName; + return FudStatus::ObjectInvalid; } m_file = fopen(m_filename.c_str(), m_mode.c_str()); - return m_file != nullptr ? FileStatus::Success : FileStatus::Error; + return m_file != nullptr ? FudStatus::Success : FudStatus::Failure; } void CBinaryFile::close() @@ -70,27 +70,27 @@ bool CBinaryFile::isOpen() const return m_file != nullptr; } -Result CBinaryFile::size() const +Result CBinaryFile::size() const { - using RetType = Result; + using RetType = Result; if (!isOpen()) { - return RetType::error(FileStatus::InvalidState); + return RetType::error(FudStatus::OperationInvalid); } auto seekStatus = fseek(m_file, 0, SEEK_END); if (seekStatus != 0) { - return RetType::error(FileStatus::Error); + return RetType::error(FudStatus::Failure); } auto fileSizeResult = ftell(m_file); if (fileSizeResult < 0) { - return RetType::error(FileStatus::Error); + return RetType::error(FudStatus::Failure); } auto fileSize = static_cast(fileSizeResult); auto resetStatus = reset(); - if (resetStatus != FileStatus::Success) { + if (resetStatus != FudStatus::Success) { return RetType::error(resetStatus); } @@ -110,12 +110,12 @@ ReadResult CBinaryFile::read(void* destination, size_t destinationSize, size_t l } if (destination == nullptr) { - result.status = FileStatus::NullPointer; + result.status = FudStatus::NullPointer; return result; } if (offset > LONG_MAX || SIZE_MAX - offset < length || destinationSize < length) { - result.status = FileStatus::InvalidArgument; + result.status = FudStatus::InvalidInput; return result; } @@ -127,13 +127,13 @@ ReadResult CBinaryFile::read(void* destination, size_t destinationSize, size_t l auto fileSize = fileSizeResult.getOkay(); if (offset + length > fileSize) { - result.status = FileStatus::InvalidArgument; + result.status = FudStatus::InvalidInput; return result; } auto seekResult = fseek(m_file, static_cast(offset), SEEK_SET); if (seekResult != 0) { - result.status = FileStatus::Error; + result.status = FudStatus::Failure; return result; } @@ -141,9 +141,9 @@ ReadResult CBinaryFile::read(void* destination, size_t destinationSize, size_t l result.bytesRead = fread(destBytes, 1, length, m_file); static_cast(reset()); if (result.bytesRead != length) { - result.status = FileStatus::PartialSuccess; + result.status = FudStatus::Partial; } else { - result.status = FileStatus::Success; + result.status = FudStatus::Success; } return result; @@ -167,12 +167,12 @@ WriteResult CBinaryFile::write(const void* source, size_t sourceSize, size_t len } if (source == nullptr) { - result.status = FileStatus::NullPointer; + result.status = FudStatus::NullPointer; return result; } if (offset > LONG_MAX || SIZE_MAX - offset < length || sourceSize < length) { - result.status = FileStatus::InvalidArgument; + result.status = FudStatus::InvalidInput; return result; } @@ -192,7 +192,7 @@ WriteResult CBinaryFile::write(const void* source, size_t sourceSize, size_t len } if (seekResult != 0) { - result.status = FileStatus::Error; + result.status = FudStatus::Failure; return result; } @@ -200,20 +200,20 @@ WriteResult CBinaryFile::write(const void* source, size_t sourceSize, size_t len result.bytesWritten = fwrite(sourceBytes, 1, length, m_file); static_cast(reset()); if (result.bytesWritten != length) { - result.status = FileStatus::PartialSuccess; + result.status = FudStatus::Partial; } else { - result.status = FileStatus::Success; + result.status = FudStatus::Success; } return result; } -FileStatus CBinaryFile::reset() const { +FudStatus CBinaryFile::reset() const { if (!isOpen()) { - return FileStatus::InvalidState; + return FudStatus::OperationInvalid; } auto result = fseek(m_file, 0, SEEK_SET); - return result == 0 ? FileStatus::Success : FileStatus::Error; + return result == 0 ? FudStatus::Success : FudStatus::Failure; } } // namespace fud -- cgit v1.2.3