@@ -1758,32 +1758,30 @@ Status FileTruncate(int fd, const int64_t size) {
17581758// Environment variables
17591759//
17601760
1761- Result<std::string> GetEnvVar (const char * name) {
1761+ Result<std::string> GetEnvVar (std::string_view name) {
17621762#ifdef _WIN32
17631763 // On Windows, getenv() reads an early copy of the process' environment
17641764 // which doesn't get updated when SetEnvironmentVariable() is called.
17651765 constexpr int32_t bufsize = 2000 ;
17661766 char c_str[bufsize];
1767- auto res = GetEnvironmentVariableA (name, c_str, bufsize);
1767+ auto res = GetEnvironmentVariableA (name. data () , c_str, bufsize);
17681768 if (res >= bufsize) {
17691769 return Status::CapacityError (" environment variable value too long" );
17701770 } else if (res == 0 ) {
17711771 return Status::KeyError (" environment variable '" , name, " 'undefined" );
17721772 }
17731773 return std::string (c_str);
17741774#else
1775- char * c_str = getenv (name);
1775+ char * c_str = getenv (name. data () );
17761776 if (c_str == nullptr ) {
17771777 return Status::KeyError (" environment variable '" , name, " 'undefined" );
17781778 }
17791779 return std::string (c_str);
17801780#endif
17811781}
17821782
1783- Result<std::string> GetEnvVar (const std::string& name) { return GetEnvVar (name.c_str ()); }
1784-
17851783#ifdef _WIN32
1786- Result<NativePathString> GetEnvVarNative (const std::string& name) {
1784+ Result<NativePathString> GetEnvVarNative (std::string_view name) {
17871785 NativePathString w_name;
17881786 constexpr int32_t bufsize = 2000 ;
17891787 wchar_t w_str[bufsize];
@@ -1798,57 +1796,46 @@ Result<NativePathString> GetEnvVarNative(const std::string& name) {
17981796 return NativePathString (w_str);
17991797}
18001798
1801- Result<NativePathString> GetEnvVarNative (const char * name) {
1802- return GetEnvVarNative (std::string (name));
1803- }
1804-
18051799#else
18061800
1807- Result<NativePathString> GetEnvVarNative (const std::string& name) {
1801+ Result<NativePathString> GetEnvVarNative (std::string_view name) {
18081802 return GetEnvVar (name);
18091803}
18101804
1811- Result<NativePathString> GetEnvVarNative (const char * name) { return GetEnvVar (name); }
18121805#endif
18131806
1814- Status SetEnvVar (const char * name, const char * value) {
1807+ Status SetEnvVar (std::string_view name, std::string_view value) {
18151808#ifdef _WIN32
1816- if (SetEnvironmentVariableA (name, value)) {
1809+ if (SetEnvironmentVariableA (name. data () , value. data () )) {
18171810 return Status::OK ();
18181811 } else {
18191812 return Status::Invalid (" failed setting environment variable" );
18201813 }
18211814#else
1822- if (setenv (name, value, 1 ) == 0 ) {
1815+ if (setenv (name. data () , value. data () , 1 ) == 0 ) {
18231816 return Status::OK ();
18241817 } else {
18251818 return Status::Invalid (" failed setting environment variable" );
18261819 }
18271820#endif
18281821}
18291822
1830- Status SetEnvVar (const std::string& name, const std::string& value) {
1831- return SetEnvVar (name.c_str (), value.c_str ());
1832- }
1833-
1834- Status DelEnvVar (const char * name) {
1823+ Status DelEnvVar (std::string_view name) {
18351824#ifdef _WIN32
1836- if (SetEnvironmentVariableA (name, nullptr )) {
1825+ if (SetEnvironmentVariableA (name. data () , nullptr )) {
18371826 return Status::OK ();
18381827 } else {
18391828 return Status::Invalid (" failed deleting environment variable" );
18401829 }
18411830#else
1842- if (unsetenv (name) == 0 ) {
1831+ if (unsetenv (name. data () ) == 0 ) {
18431832 return Status::OK ();
18441833 } else {
18451834 return Status::Invalid (" failed deleting environment variable" );
18461835 }
18471836#endif
18481837}
18491838
1850- Status DelEnvVar (const std::string& name) { return DelEnvVar (name.c_str ()); }
1851-
18521839//
18531840// Temporary directories
18541841//
0 commit comments