| OLD | NEW |
| 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 Loading... |
| 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) |
| OLD | NEW |