summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorzhenhaonong <zhenhaonong@tencent.com>2022-09-22 02:01:26 (GMT)
committerzhenhaonong <zhenhaonong@tencent.com>2022-09-23 03:54:24 (GMT)
commit1b64aa68b9ff438f10d9880d40ea06751706be81 (patch)
treea878d5dd38b2e04b9d32510f360eb35a07c9ffc3 /Source/cmSystemTools.cxx
parent9bdeaa79e239e9279f1e42759400a6902494af6d (diff)
downloadCMake-1b64aa68b9ff438f10d9880d40ea06751706be81.zip
CMake-1b64aa68b9ff438f10d9880d40ea06751706be81.tar.gz
CMake-1b64aa68b9ff438f10d9880d40ea06751706be81.tar.bz2
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.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx9
1 files changed, 9 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 8e77afa..5737cc1 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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;
}