29 namespace EnvironmentUnixImp
31 char * stringdup(
const std::string & ) ;
37 const char * p = std::getenv( name.c_str() ) ;
38 return p ? std::string(p) : default_ ;
44 const char * p = std::getenv( name.c_str() ) ;
45 return p ?
G::Path(p) : default_ ;
49char * G::EnvironmentUnixImp::stringdup(
const std::string & s )
51 void * p = std::memcpy(
new char[s.size()+1U] , s.c_str() , s.size()+1U ) ;
52 return static_cast<char*
>(p) ;
58 namespace imp = EnvironmentUnixImp ;
59 char * deliberately_leaky_copy = imp::stringdup( std::string().append(name).append(1U,
'=').append(value) ) ;
60 ::putenv( deliberately_leaky_copy ) ;
65 std::string path = sbin ?
"/usr/bin:/bin:/usr/sbin:/sbin" :
"/usr/bin:/bin" ;
66 return Environment( {{
"PATH",path},{
"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 G::Path getPath(const std::string &name, const G::Path &={})
Returns the environment variable value as a G::Path object.
static Environment minimal(bool sbin=false)
Returns a minimal, safe set of environment variables.
A Path object represents a file system path.