summaryrefslogtreecommitdiff
path: root/source/fud_c_file.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-28 11:14:31 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-28 11:14:31 -0500
commitb6967c8a9190efa4e9128850fa723fe3ea3140f7 (patch)
tree101be12055abd27968fce2666d573c80f8afe22d /source/fud_c_file.cpp
parent987466c74332025fae74d196ff680a57ccb247a2 (diff)
Expand directory interface, remove FileStatus for FudStatus.
Diffstat (limited to 'source/fud_c_file.cpp')
-rw-r--r--source/fud_c_file.cpp46
1 files changed, 23 insertions, 23 deletions
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<size_t, FileStatus> CBinaryFile::size() const
+Result<size_t, FudStatus> CBinaryFile::size() const
{
- using RetType = Result<size_t, FileStatus>;
+ using RetType = Result<size_t, FudStatus>;
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<size_t>(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<long>(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<void>(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<void>(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