Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Unified Diff: runtime/bin/platform_win.cc

Issue 11529008: Fix extraction of environment variables on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/windows_environment_script.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index 750caa65c246a765ea82f236350dafe8d1c6bad2..16e38d16d61ea89ad87bc83db925bf14279eefbf 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -35,26 +35,36 @@ bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
}
+static char* WideToUtf8(wchar_t* wide) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
+ char* utf8 = reinterpret_cast<char*>(malloc(len + 1));
+ WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, len, NULL, NULL);
+ utf8[len] = '\0';
+ return utf8;
+}
+
+
char** Platform::Environment(intptr_t* count) {
- char* strings = GetEnvironmentStrings();
+ wchar_t* strings = GetEnvironmentStringsW();
if (strings == NULL) return NULL;
- char* tmp = strings;
+ wchar_t* tmp = strings;
intptr_t i = 0;
while (*tmp != '\0') {
i++;
- tmp += (strlen(tmp) + 1);
+ tmp += (wcslen(tmp) + 1);
}
*count = i;
char** result = new char*[i];
tmp = strings;
for (intptr_t current = 0; current < i; current++) {
- result[current] = StringUtils::SystemStringToUtf8(tmp);
- tmp += (strlen(tmp) + 1);
+ result[current] = WideToUtf8(tmp);
+ tmp += (wcslen(tmp) + 1);
}
- FreeEnvironmentStrings(strings);
+ FreeEnvironmentStringsW(strings);
return result;
}
+
void Platform::FreeEnvironment(char** env, int count) {
for (int i = 0; i < count; i++) free(env[i]);
delete[] env;
« no previous file with comments | « no previous file | tests/standalone/io/windows_environment_script.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698