29 const char * p = std::getenv( name.c_str() ) ;
30 return p ? std::string(p) : default_ ;
33char * G::Environment::stringdup(
const std::string & s )
35 void * p = std::memcpy(
new char[s.size()+1U] , s.c_str() , s.size()+1U ) ;
36 return static_cast<char*
>(p) ;
42 char * deliberately_leaky_copy = stringdup( std::string().append(name).append(1U,
'=').append(value) ) ;
43 ::putenv( deliberately_leaky_copy ) ;
49 env.
add(
"PATH" ,
"/usr/bin:/bin" ) ;
50 env.
add(
"IFS" ,
" \t\n" ) ;
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().
static void put(const std::string &name, const std::string &value)
Sets the environment variable value.
static std::string get(const std::string &name, const std::string &default_)
Returns the environment variable value or the given default.
static Environment minimal()
Returns a minimal, safe set of environment variables.
void add(const std::string &name, const std::string &value)
Adds a variable to this set.