Use SetEnvironmentVariableW on Cygwin too

This commit is contained in:
Peter Dimov 2017-11-22 16:15:26 +02:00
parent 93cab09a6b
commit 03eb5df380

View File

@ -56,33 +56,41 @@ inline std::wstring convert(const char* c)
return std::wstring(s.begin(), s.end());
}
#if defined(_MSC_VER) || defined(__MINGW32__)
// Note: these three setenv* functions are not general solutions for the missing
// setenv* problem on VC++. See Microsoft's _putenv for that need, and ticker #7018
// for discussion and rationale for returning void for this test program, which needs
// to work for both the MSVC Runtime and the Windows Runtime (which does not support
// _putenv).
inline void setenv(const char* name, const fs::path::value_type* val, int)
inline void setenv_(const char* name, const fs::path::value_type* val, int)
{
SetEnvironmentVariableW(convert(name).c_str(), val);
SetEnvironmentVariableW(convert(name).c_str(), val);
}
inline void setenv(const char* name, const char* val, int)
inline void setenv_(const char* name, const char* val, int)
{
SetEnvironmentVariableW(convert(name).c_str(), convert(val).c_str());
SetEnvironmentVariableW(convert(name).c_str(), convert(val).c_str());
}
inline void unsetenv(const char* name)
inline void unsetenv_(const char* name)
{
SetEnvironmentVariableW(convert(name).c_str(), 0);
SetEnvironmentVariableW(convert(name).c_str(), 0);
}
#endif
#else
#include <stdlib.h> // allow unqualifed calls to env funcs on SunOS
inline void setenv_(const char* name, const char* val, int ovw)
{
setenv(name, val, ovw);
}
inline void unsetenv_(const char* name)
{
unsetenv(name);
}
#endif
// on Windows, except for standard libaries known to have wchar_t overloads for
@ -1929,8 +1937,8 @@ namespace
}
~previous_value()
{
m_empty? unsetenv(m_name.c_str())
: setenv(m_name.c_str(), m_string.c_str(), 1);
m_empty? unsetenv_(m_name.c_str())
: setenv_(m_name.c_str(), m_string.c_str(), 1);
}
};
@ -1940,7 +1948,7 @@ namespace
: m_previous_value(name)
{
// std::cout << name << " old value is \"" << getenv(name) << "\"" << std::endl;
value ? setenv(name, value, 1) : unsetenv(name);
value ? setenv_(name, value, 1) : unsetenv_(name);
// std::cout << name << " new value is \"" << getenv(name) << "\"" << std::endl;
}
};