28#if ! GCONFIG_HAVE_GETENV_S
29inline errno_t getenv_s( std::size_t * n_out ,
char * buffer , std::size_t n_in ,
const char * name )
31 if( n_out ==
nullptr || name ==
nullptr || (!buffer&&n_in) )
34 const char * p = ::getenv( name ) ;
41 size_t n = std::strlen( p ) ;
60 errno_t rc = getenv_s( &n ,
nullptr , 0U , name.c_str() ) ;
64 std::vector<char> buffer( n ) ;
65 rc = getenv_s( &n , &buffer[0] , n , name.c_str() ) ;
66 if( rc != 0 || n == 0U )
69 buffer.push_back(
'\0' ) ;
70 return std::string( &buffer[0] ) ;
75 return Environment() ;
82 std::string s = name +
"=" + value ;
83 char * deliberately_leaky_copy = _strdup( s.c_str() ) ;
84 GDEF_IGNORE_RETURN _putenv( deliberately_leaky_copy ) ;
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(bool sbin=false)
Returns a minimal, safe set of environment variables.