From b72f23ce67bc30d3bedbeabcf0b6d9c1fbf2a64f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 15 Jun 2018 12:18:52 +0300 Subject: Use portable environment variable manipulation functions --- build2/functions-builtin.cxx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'build2/functions-builtin.cxx') 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 // getenv() - #include #include -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 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 (move (name))); + return getvar (convert (move (name))); }; } } -- cgit v1.1