diff options
Diffstat (limited to 'source/libfud.cpp')
-rw-r--r-- | source/libfud.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/libfud.cpp b/source/libfud.cpp index 834082e..e1dad1d 100644 --- a/source/libfud.cpp +++ b/source/libfud.cpp @@ -17,10 +17,29 @@ #include "libfud.hpp" +#include <cstdlib> + namespace fud { -void fud() +Result<String, FudStatus> getEnv(const char* name) { + using RetType = Result<String, FudStatus>; + + if (name == nullptr) { + return RetType::error(FudStatus::NullPointer); + } + + const char* resultString = getenv(name); + if (resultString == nullptr) { + return RetType::error(FudStatus::NotFound); + } + + String envVar{resultString}; + if (!envVar.valid()) { + return RetType::error(FudStatus::Failure); + } + + return RetType::okay(std::move(envVar)); } } // namespace fud |