summaryrefslogtreecommitdiff
path: root/source/libfud.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-25 11:25:25 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-25 11:25:25 -0500
commit255fa256b106506e0c951f704314c5c633217468 (patch)
treeacda2292f4ef315a64de763d4ee8e9a82f587a8c /source/libfud.cpp
parent204dad55119df079ca54309bc4b740280fa54c31 (diff)
Further expansion of string api.
Diffstat (limited to 'source/libfud.cpp')
-rw-r--r--source/libfud.cpp21
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