aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/b.cxx14
-rw-r--r--build2/functions-builtin.cxx16
-rw-r--r--build2/utility.hxx7
3 files changed, 17 insertions, 20 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index de985e8..cd738f2 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -8,8 +8,6 @@
# include <libbutl/win32-utility.hxx>
#endif
-#include <stdlib.h> // getenv() _putenv()(_WIN32)
-
#ifdef __GLIBCXX__
# include <locale>
#endif
@@ -144,15 +142,15 @@ main (int argc, char* argv[])
//
#ifdef _WIN32
{
- string mp ("PATH=");
- if (const char* p = getenv ("PATH"))
+ string mp;
+ if (optional<string> p = getenv ("PATH"))
{
- mp += p;
+ mp = move (*p);
mp += ';';
}
mp += "/bin";
- _putenv (mp.c_str ());
+ setenv ("PATH", mp);
}
#endif
@@ -465,11 +463,11 @@ main (int argc, char* argv[])
//
if (verb >= 5)
{
- const char* p (getenv ("PATH"));
+ optional<string> p (getenv ("PATH"));
trace << "work: " << work;
trace << "home: " << home;
- trace << "path: " << (p != nullptr ? p : "<NULL>");
+ trace << "path: " << (p ? *p : "<NULL>");
trace << "jobs: " << jobs;
}
diff --git a/build2/functions-builtin.cxx b/build2/functions-builtin.cxx
index 350bddf..45ad7df 100644
--- a/build2/functions-builtin.cxx
+++ b/build2/functions-builtin.cxx
@@ -2,28 +2,24 @@
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <cstdlib> // getenv()
-
#include <build2/function.hxx>
#include <build2/variable.hxx>
-using namespace std;
-
namespace build2
{
// Return NULL value if an environment variable is not set, untyped value
// otherwise.
//
static inline value
- getenv (const string& name)
+ getvar (const string& name)
{
- const char* v (::getenv (name.c_str ()));
+ optional<string> v (getenv (name));
- if (v == nullptr)
+ if (!v)
return value ();
names r;
- r.emplace_back (to_name (v));
+ r.emplace_back (to_name (*v));
return value (move (r));
}
@@ -49,12 +45,12 @@ namespace build2
//
f["getenv"] = [](string name)
{
- return getenv (name);
+ return getvar (name);
};
f["getenv"] = [](names name)
{
- return getenv (convert<string> (move (name)));
+ return getvar (convert<string> (move (name)));
};
}
}
diff --git a/build2/utility.hxx b/build2/utility.hxx
index 4ca12ca..81a5d87 100644
--- a/build2/utility.hxx
+++ b/build2/utility.hxx
@@ -16,8 +16,7 @@
#include <libbutl/ft/lang.hxx>
-#include <libbutl/utility.mxx> // combine_hash(), reverse_iterate(), case*(),
- // etc
+#include <libbutl/utility.mxx> // combine_hash(), reverse_iterate(), etc
#include <unordered_set>
@@ -74,6 +73,10 @@ namespace build2
using butl::make_guard;
using butl::make_exception_guard;
+ using butl::getenv;
+ using butl::setenv;
+ using butl::unsetenv;
+
using butl::throw_generic_error;
using butl::throw_system_error;