From 02ada52a38576331f58744ffa83d9cbba6b53827 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 15 Jun 2018 11:55:47 +0300 Subject: Use portable environment variable manipulation functions --- bpkg/bpkg.cxx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'bpkg/bpkg.cxx') 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() -#else -# include // getenv(), _putenv() #endif #include // 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 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); +} -- cgit v1.1