diff options
Diffstat (limited to 'source/libfud.cpp')
-rw-r--r-- | source/libfud.cpp | 15 |
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 |