aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/bpkg.cxx24
-rw-r--r--bpkg/database.cxx14
-rw-r--r--bpkg/utility.hxx4
3 files changed, 23 insertions, 19 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index b9836ad..831b742 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -4,8 +4,6 @@
#ifndef _WIN32
# include <signal.h> // signal()
-#else
-# include <stdlib.h> // getenv(), _putenv()
#endif
#include <cstring> // strcmp()
@@ -50,6 +48,12 @@ using namespace std;
using namespace butl;
using namespace bpkg;
+namespace bpkg
+{
+ int
+ main (int argc, char* argv[]);
+}
+
// Get -d|--directory value if the option class O has it and empty path
// otherwise. Note that for some commands (like rep-info) that allow
// specifying empty path, the returned value is a string, not a dir_path.
@@ -134,7 +138,7 @@ init (const common_options& co,
return o;
}
-int
+int bpkg::
main (int argc, char* argv[])
try
{
@@ -155,15 +159,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
@@ -368,3 +372,9 @@ catch (const std::exception& e)
return 1;
}
*/
+
+int
+main (int argc, char* argv[])
+{
+ return bpkg::main (argc, argv);
+}
diff --git a/bpkg/database.cxx b/bpkg/database.cxx
index f5102f0..3c55237 100644
--- a/bpkg/database.cxx
+++ b/bpkg/database.cxx
@@ -4,8 +4,6 @@
#include <bpkg/database.hxx>
-#include <stdlib.h> // getenv() setenv()/_putenv()
-
#include <odb/schema-catalog.hxx>
#include <odb/sqlite/exceptions.hxx>
@@ -25,7 +23,7 @@ namespace bpkg
// BPKG_OPEN_CONFIG environment variable. A bit heavy-weight but seems like
// the best option.
//
- static const char open_name[] = "BPKG_OPEN_CONFIG";
+ static const string open_name ("BPKG_OPEN_CONFIG");
class conn_factory: public single_connection_factory // No need for pool.
{
@@ -36,21 +34,13 @@ namespace bpkg
v.complete ();
v.normalize ();
-#ifndef _WIN32
- setenv (open_name, v.string ().c_str (), 1 /* overwrite */);
-#else
- _putenv ((string (open_name) + '=' + v.string ()).c_str ());
-#endif
+ setenv (open_name, v.string ());
}
virtual
~conn_factory ()
{
-#ifndef _WIN32
unsetenv (open_name);
-#else
- _putenv ((string (open_name) + '=').c_str ());
-#endif
}
};
diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx
index 367f03d..19d664e 100644
--- a/bpkg/utility.hxx
+++ b/bpkg/utility.hxx
@@ -40,6 +40,10 @@ namespace bpkg
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;