From 53c4dcf374c66f1e9190f5a62a52d02fe11a69e6 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 16 Oct 2024 22:25:08 -0500 Subject: First crack at allocators. --- source/fud_c_file.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'source/fud_c_file.cpp') diff --git a/source/fud_c_file.cpp b/source/fud_c_file.cpp index a63923a..15c57ab 100644 --- a/source/fud_c_file.cpp +++ b/source/fud_c_file.cpp @@ -30,7 +30,10 @@ CBinaryFileResult CBinaryFile::make(const String& filename, CFileMode mode) } CBinaryFile binaryFile{}; - binaryFile.m_filename = filename; + auto copyStatus = binaryFile.m_filename.copy(filename); + if (copyStatus != FudStatus::Success) { + return CBinaryFileResult::error(copyStatus); + } binaryFile.m_mode = modeResult.takeOkay(); binaryFile.m_modeFlags = mode; return CBinaryFileResult::okay(std::move(binaryFile)); @@ -41,13 +44,16 @@ CBinaryFileResult CBinaryFile::make(const String& filename, CFileMode mode, cons if (!filename.valid()) { return CBinaryFileResult::error(FudStatus::InvalidInput); } - auto modeResult{String::makeFromCString(CBinaryFileModeFromFlags(mode), extraFlags)}; + auto modeResult{String::makeFromCStrings(CBinaryFileModeFromFlags(mode), extraFlags)}; if (modeResult.isError()) { return CBinaryFileResult::error(modeResult); } CBinaryFile binaryFile{}; - binaryFile.m_filename = filename; + auto copyStatus = binaryFile.m_filename.copy(filename); + if (copyStatus != FudStatus::Success) { + return CBinaryFileResult::error(copyStatus); + } binaryFile.m_mode = modeResult.takeOkay(); binaryFile.m_modeFlags = mode; return CBinaryFileResult::okay(std::move(binaryFile)); @@ -92,7 +98,10 @@ CTextFileResult CTextFile::make(const String& filename, CFileMode mode) } CTextFile textFile{}; - textFile.m_filename = filename; + auto copyStatus = textFile.m_filename.copy(filename); + if (copyStatus != FudStatus::Success) { + return CTextFileResult::error(copyStatus); + } textFile.m_mode = modeResult.takeOkay(); textFile.m_modeFlags = mode; return CTextFileResult::okay(std::move(textFile)); @@ -103,13 +112,16 @@ CTextFileResult CTextFile::make(const String& filename, CFileMode mode, const ch if (!filename.valid()) { return CTextFileResult::error(FudStatus::InvalidInput); } - auto modeResult{String::makeFromCString(CTextFileModeFromFlags(mode), extraFlags)}; + auto modeResult{String::makeFromCStrings(CTextFileModeFromFlags(mode), extraFlags)}; if (modeResult.isError()) { return CTextFileResult::error(modeResult); } CTextFile textFile{}; - textFile.m_filename = filename; + auto copyStatus = textFile.m_filename.copy(filename); + if (copyStatus != FudStatus::Success) { + return CTextFileResult::error(copyStatus); + } textFile.m_mode = modeResult.takeOkay(); textFile.m_modeFlags = mode; return CTextFileResult::okay(std::move(textFile)); -- cgit v1.2.3