summaryrefslogtreecommitdiff
path: root/source/libfud.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-01-04 09:56:12 -0600
committerDominick Allen <djallen@librehumanitas.org>2025-01-04 09:56:12 -0600
commit0b400af9519444deef4cc6ad2c43c30e2092ab4f (patch)
treee6b0d78a2c292a7df5724f150e123b55d7871819 /source/libfud.cpp
parent253385f4bca5ccd2fee22fea8333dfe435c0df0a (diff)
Fix bug related to string copying.
Diffstat (limited to 'source/libfud.cpp')
-rw-r--r--source/libfud.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/source/libfud.cpp b/source/libfud.cpp
index be43490..c4e4b5b 100644
--- a/source/libfud.cpp
+++ b/source/libfud.cpp
@@ -35,20 +35,23 @@ FUD fud()
return fudInfo;
}
-Result<String, FudStatus> getEnv(const char* name, Allocator* allocator)
+Result<Option<String>, FudStatus> getEnv(const char* name, Allocator* allocator)
{
- using RetType = Result<String, FudStatus>;
-
if (name == nullptr) {
- return RetType::error(FudStatus::NullPointer);
+ return Error{FudStatus::NullPointer};
}
const char* resultString = getenv(name);
if (resultString == nullptr) {
- return RetType::error(FudStatus::NotFound);
+ return Okay{Option<String>{NullOpt}};
+ }
+
+ auto result{String::makeFromCString(resultString, allocator)};
+ if (result.isError()) {
+ return Error{result.takeError()};
}
- return String::makeFromCString(resultString, allocator);
+ return Okay{Option<String>::take(result.takeOkay())};
}
} // namespace fud