| 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/file.h" | 8 #include "bin/file.h" |
| 9 #include "bin/platform.h" | 9 #include "bin/platform.h" |
| 10 #include "bin/log.h" | 10 #include "bin/log.h" |
| 11 #include "bin/socket.h" | 11 #include "bin/socket.h" |
| 12 #include "bin/utils.h" | 12 #include "bin/utils.h" |
| 13 #include "bin/utils_win.h" |
| 13 | 14 |
| 14 | 15 |
| 15 namespace dart { | 16 namespace dart { |
| 16 namespace bin { | 17 namespace bin { |
| 17 | 18 |
| 18 bool Platform::Initialize() { | 19 bool Platform::Initialize() { |
| 19 // Nothing to do on Windows. | 20 // Nothing to do on Windows. |
| 20 return true; | 21 return true; |
| 21 } | 22 } |
| 22 | 23 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // variables like %=C:% and %=ExitCode%, and the Dart environment does | 60 // variables like %=C:% and %=ExitCode%, and the Dart environment does |
| 60 // not include these. | 61 // not include these. |
| 61 if (*tmp != '=') i++; | 62 if (*tmp != '=') i++; |
| 62 tmp += (wcslen(tmp) + 1); | 63 tmp += (wcslen(tmp) + 1); |
| 63 } | 64 } |
| 64 *count = i; | 65 *count = i; |
| 65 char** result = new char*[i]; | 66 char** result = new char*[i]; |
| 66 tmp = strings; | 67 tmp = strings; |
| 67 for (intptr_t current = 0; current < i;) { | 68 for (intptr_t current = 0; current < i;) { |
| 68 // Skip the strings that were not counted above. | 69 // Skip the strings that were not counted above. |
| 69 if (*tmp != '=') result[current++] = StringUtils::WideToUtf8(tmp); | 70 if (*tmp != '=') result[current++] = StringUtilsWin::WideToUtf8(tmp); |
| 70 tmp += (wcslen(tmp) + 1); | 71 tmp += (wcslen(tmp) + 1); |
| 71 } | 72 } |
| 72 FreeEnvironmentStringsW(strings); | 73 FreeEnvironmentStringsW(strings); |
| 73 return result; | 74 return result; |
| 74 } | 75 } |
| 75 | 76 |
| 76 | 77 |
| 77 void Platform::FreeEnvironment(char** env, intptr_t count) { | 78 void Platform::FreeEnvironment(char** env, intptr_t count) { |
| 78 for (intptr_t i = 0; i < count; i++) { | 79 for (intptr_t i = 0; i < count; i++) { |
| 79 free(env[i]); | 80 free(env[i]); |
| 80 } | 81 } |
| 81 delete[] env; | 82 delete[] env; |
| 82 } | 83 } |
| 83 | 84 |
| 84 | 85 |
| 85 char* Platform::ResolveExecutablePath() { | 86 char* Platform::ResolveExecutablePath() { |
| 86 // GetModuleFileNameW cannot directly provide information on the | 87 // GetModuleFileNameW cannot directly provide information on the |
| 87 // required buffer size, so start out with a buffer large enough to | 88 // required buffer size, so start out with a buffer large enough to |
| 88 // hold any Windows path. | 89 // hold any Windows path. |
| 89 const int kTmpBufferSize = 32768; | 90 const int kTmpBufferSize = 32768; |
| 90 wchar_t* tmp_buffer = reinterpret_cast<wchar_t*>(malloc(kTmpBufferSize)); | 91 wchar_t* tmp_buffer = reinterpret_cast<wchar_t*>(malloc(kTmpBufferSize)); |
| 91 // Ensure no last error before calling GetModuleFileNameW. | 92 // Ensure no last error before calling GetModuleFileNameW. |
| 92 SetLastError(ERROR_SUCCESS); | 93 SetLastError(ERROR_SUCCESS); |
| 93 // Get the required length of the buffer. | 94 // Get the required length of the buffer. |
| 94 int path_length = GetModuleFileNameW(NULL, tmp_buffer, kTmpBufferSize); | 95 int path_length = GetModuleFileNameW(NULL, tmp_buffer, kTmpBufferSize); |
| 95 if (GetLastError() != ERROR_SUCCESS) { | 96 if (GetLastError() != ERROR_SUCCESS) { |
| 96 free(tmp_buffer); | 97 free(tmp_buffer); |
| 97 return NULL; | 98 return NULL; |
| 98 } | 99 } |
| 99 char* path = StringUtils::WideToUtf8(tmp_buffer); | 100 char* path = StringUtilsWin::WideToUtf8(tmp_buffer); |
| 100 free(tmp_buffer); | 101 free(tmp_buffer); |
| 101 // Return the canonical path as the returned path might contain symlinks. | 102 // Return the canonical path as the returned path might contain symlinks. |
| 102 char* canon_path = File::GetCanonicalPath(path); | 103 char* canon_path = File::GetCanonicalPath(path); |
| 103 free(path); | 104 free(path); |
| 104 return canon_path; | 105 return canon_path; |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace bin | 108 } // namespace bin |
| 108 } // namespace dart | 109 } // namespace dart |
| 109 | 110 |
| 110 #endif // defined(TARGET_OS_WINDOWS) | 111 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |