Browse Source

Merge topic 'unicode-env'

1b64aa68b9 cmSystemTools: Fix encoding of whole-environment lookup on Windows

Acked-by: Kitware Robot <[email protected]>
Merge-request: !7705
Brad King 3 years ago
parent
commit
5838093985
1 changed files with 9 additions and 0 deletions
  1. 9 0
      Source/cmSystemTools.cxx

+ 9 - 0
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;
 }