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

Side by Side 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: Addressed review comments 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/platform.h" 8 #include "bin/platform.h"
9 #include "bin/log.h" 9 #include "bin/log.h"
10 #include "bin/socket.h" 10 #include "bin/socket.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 75
76 void Platform::FreeEnvironment(char** env, intptr_t count) { 76 void Platform::FreeEnvironment(char** env, intptr_t count) {
77 for (intptr_t i = 0; i < count; i++) { 77 for (intptr_t i = 0; i < count; i++) {
78 free(env[i]); 78 free(env[i]);
79 } 79 }
80 delete[] env; 80 delete[] env;
81 } 81 }
82 82
83
84 char* Platform::ResolveExecutablePath() {
85 // GetModuleFileNameW cannot directly provide information on the
86 // required buffer size, so start out with a buffer large enough to
87 // hold any Windows path.
88 const int kTmpBufferSize = 32768;
89 wchar_t* tmp_buffer = reinterpret_cast<wchar_t*>(malloc(kTmpBufferSize));
90 // Ensure no last error before calling GetModuleFileNameW.
91 SetLastError(ERROR_SUCCESS);
92 // Get the required length of the buffer.
93 int path_length = GetModuleFileNameW(NULL, tmp_buffer, kTmpBufferSize);
94 if (GetLastError() != ERROR_SUCCESS) {
95 free(tmp_buffer);
96 return NULL;
97 }
98 char* path = StringUtils::WideToUtf8(tmp_buffer);
99 free(tmp_buffer);
100 return path;
101 }
102
83 } // namespace bin 103 } // namespace bin
84 } // namespace dart 104 } // namespace dart
85 105
86 #endif // defined(TARGET_OS_WINDOWS) 106 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698