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

Unified Diff: runtime/bin/platform_win.cc

Issue 1145053002: Make Platform.executable return a fully qualified path the the executable (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix comment Created 5 years, 7 months 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
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index 97d54cc8e7f55a561ba96da900ad2ca0a08476a9..afa924bab82e4cfa82eb7f5bfcd8cbc229281569 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -80,6 +80,26 @@ void Platform::FreeEnvironment(char** env, intptr_t count) {
delete[] env;
}
+
+char* Platform::ResolveExecutablePath() {
+ // GetModuleFileNameW cannot directly provide information on the
+ // required buffer size, so start out with a buffer large enough to
+ // hold any Windows path.
+ const int kTmpBufferSize = 32768;
kustermann 2015/05/20 10:19:56 Isn't there a much shorter maximum path length?
Lasse Reichstein Nielsen 2015/05/20 10:48:43 Not according to https://msdn.microsoft.com/en-us/
Søren Gjesse 2015/05/20 11:14:24 According to https://msdn.microsoft.com/en-us/libr
+ wchar_t* tmp_buffer = reinterpret_cast<wchar_t*>(malloc(kTmpBufferSize));
+ // Ensure no last error before calling GetModuleFileNameW.
+ SetLastError(ERROR_SUCCESS);
+ // Get the required length of the buffer.
+ int path_length = GetModuleFileNameW(NULL, tmp_buffer, kTmpBufferSize);
+ if (GetLastError() != ERROR_SUCCESS) {
+ free(tmp_buffer);
+ return NULL;
+ }
+ char* path = StringUtils::WideToUtf8(tmp_buffer);
+ free(tmp_buffer);
+ return path;
+}
+
} // namespace bin
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698