summaryrefslogtreecommitdiff
path: root/src/tools.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cc')
-rw-r--r--src/tools.cc31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/tools.cc b/src/tools.cc
index abc0e5f..f4e6835 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -7,34 +7,15 @@
#include "tools.h"
-#include <cstring>
+#include <stdlib.h>
-#include <errno.h>
-
-using namespace Binc;
-using std::string;
-
-Tools::Tools() {}
-
-Tools &Tools::getInstance()
+void Binc::Tools::setenv(const std::string &key, const std::string &value)
{
- static Tools tools;
- return tools;
+ ::setenv(key.c_str(), value.c_str(), 1);
}
-void Tools::setenv(const string &key, const string &value) const
+std::optional<std::string> Binc::Tools::getenv(const std::string &key)
{
- char *c = strdup((key + "=" + value).c_str());
- putenv(c);
-}
-
-string Tools::getenv(const string &key) const
-{
- static const string NIL = "";
-
- const char *c = ::getenv((char *)key.c_str());
- if (c == nullptr)
- return NIL;
- else
- return string(c);
+ const char *c = ::getenv(key.c_str());
+ return c ? std::make_optional(c) : std::nullopt;
}