aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/bdep.cxx24
-rw-r--r--bdep/sync.cxx17
-rw-r--r--bdep/utility.hxx4
3 files changed, 26 insertions, 19 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index cab10fa..d0327d8 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -4,8 +4,6 @@
#ifndef _WIN32
# include <signal.h> // signal()
-#else
-# include <stdlib.h> // getenv(), _putenv()
#endif
#include <cstring> // strcmp()
@@ -36,6 +34,12 @@
using namespace std;
using namespace bdep;
+namespace bdep
+{
+ int
+ main (int argc, char* argv[]);
+}
+
// Initialize the command option class O with the common options and then
// parse the rest of the command line placing non-option arguments to args.
// Once this is done, use the "final" values of the common options to do
@@ -122,7 +126,7 @@ init (const common_options& co, cli::group_scanner& scan, strings& args)
return o;
}
-int
+int bdep::
main (int argc, char* argv[])
try
{
@@ -143,15 +147,15 @@ try
//
#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
@@ -313,3 +317,9 @@ catch (const std::exception& e)
return 1;
}
*/
+
+int
+main (int argc, char* argv[])
+{
+ return bdep::main (argc, argv);
+}
diff --git a/bdep/sync.cxx b/bdep/sync.cxx
index 7df2c9e..8cfdc7a 100644
--- a/bdep/sync.cxx
+++ b/bdep/sync.cxx
@@ -4,8 +4,6 @@
#include <bdep/sync.hxx>
-#include <stdlib.h> // getenv() setenv()/_putenv()
-
#include <cstring> // strchr()
#include <bdep/database.hxx>
@@ -489,8 +487,8 @@ namespace bdep
string v;
const string& p (d.string ());
- if (const char* e = getenv (synced_name))
- v = e;
+ if (optional<string> e = getenv (synced_name))
+ v = move (*e);
for (size_t b (0), e (0);
(e = v.find ('"', e)) != string::npos; // Skip leading ' '.
@@ -514,12 +512,7 @@ namespace bdep
if (add)
{
v += (v.empty () ? "\"" : " \"") + p + '"';
-
-#ifndef _WIN32
- setenv (synced_name, v.c_str (), 1 /* overwrite */);
-#else
- _putenv ((string (synced_name) + '=' + v).c_str ());
-#endif
+ setenv (synced_name, v);
}
return false;
@@ -693,14 +686,14 @@ namespace bdep
// noop loads the buildfiles. Maybe need something like bootstrap
// and load meta-operation?
//
- const char* open (getenv ("BPKG_OPEN_CONFIG"));
+ optional<string> open (getenv ("BPKG_OPEN_CONFIG"));
for (dir_path d: o.config ())
{
d.complete ();
d.normalize ();
- if (open != nullptr && d.string () == open)
+ if (open && d.string () == *open)
continue;
if (synced (d, o.implicit (), false /* add */))
diff --git a/bdep/utility.hxx b/bdep/utility.hxx
index 75adf1d..ea8f5d1 100644
--- a/bdep/utility.hxx
+++ b/bdep/utility.hxx
@@ -50,6 +50,10 @@ namespace bdep
using butl::make_guard;
using butl::make_exception_guard;
+ using butl::getenv;
+ using butl::setenv;
+ using butl::unsetenv;
+
// <libbutl/filesystem.mxx>
//
using butl::auto_rmfile;