mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-04 04:03:22 +03:00
cmSystemTools: Fix encoding of whole-environment lookup on Windows
On Windows, `environ` is encoded by `CP_ACP`, which may be different from `KWSYS_ENCODING_DEFAULT_CODEPAGE`. When environment variables include a unicode character, they may be corrupted. Use `_wenviron` instead.
This commit is contained in:
1 parent
9bdeaa79e2
commit
1b64aa68b9
1 file changed
+9
@@ -1642,9 +1642,18 @@ std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
|
||||
{
|
||||
std::vector<std::string> env;
|
||||
int cc;
|
||||
# ifdef _WIN32
|
||||
// if program starts with main, _wenviron is initially NULL, call to
|
||||
// _wgetenv and create wide-character string environment
|
||||
_wgetenv(L"");
|
||||
for (cc = 0; _wenviron[cc]; ++cc) {
|
||||
env.emplace_back(cmsys::Encoding::ToNarrow(_wenviron[cc]));
|
||||
}
|
||||
# else
|
||||
for (cc = 0; environ[cc]; ++cc) {
|
||||
env.emplace_back(environ[cc]);
|
||||
}
|
||||
# endif
|
||||
return env;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user