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

Side by Side Diff: runtime/bin/utils_win.cc

Issue 23463044: Remove duplicated code on Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/utils_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <time.h> // NOLINT 9 #include <time.h> // NOLINT
10 10
11 #include "bin/utils.h" 11 #include "bin/utils.h"
12 #include "bin/utils_win.h"
12 #include "bin/log.h" 13 #include "bin/log.h"
13 14
14 15
15 namespace dart { 16 namespace dart {
16 namespace bin { 17 namespace bin {
17 18
18 static void FormatMessageIntoBuffer(DWORD code, 19 void FormatMessageIntoBuffer(DWORD code, wchar_t* buffer, int buffer_length) {
19 wchar_t* buffer,
20 int buffer_length) {
21 DWORD message_size = 20 DWORD message_size =
22 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 21 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
23 NULL, 22 NULL,
24 code, 23 code,
25 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 24 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
26 buffer, 25 buffer,
27 buffer_length, 26 buffer_length,
28 NULL); 27 NULL);
29 if (message_size == 0) { 28 if (message_size == 0) {
30 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 29 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
31 Log::PrintErr("FormatMessage failed %d\n", GetLastError()); 30 Log::PrintErr("FormatMessage failed for error code %d (error %d)\n",
31 code,
32 GetLastError());
32 } 33 }
33 _snwprintf(buffer, buffer_length, L"OS Error %d", code); 34 _snwprintf(buffer, buffer_length, L"OS Error %d", code);
34 } 35 }
35 buffer[buffer_length - 1] = '\0'; 36 // Ensure string termination.
37 buffer[buffer_length - 1] = 0;
36 } 38 }
37 39
38 40
39 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { 41 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) {
40 set_code(GetLastError()); 42 set_code(GetLastError());
41 43
42 static const int kMaxMessageLength = 256; 44 static const int kMaxMessageLength = 256;
43 wchar_t message[kMaxMessageLength]; 45 wchar_t message[kMaxMessageLength];
44 FormatMessageIntoBuffer(code_, message, kMaxMessageLength); 46 FormatMessageIntoBuffer(code_, message, kMaxMessageLength);
45 char* utf8 = StringUtils::WideToUtf8(message); 47 char* utf8 = StringUtils::WideToUtf8(message);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 148 }
147 149
148 void TimerUtils::Sleep(int64_t millis) { 150 void TimerUtils::Sleep(int64_t millis) {
149 ::Sleep(millis); 151 ::Sleep(millis);
150 } 152 }
151 153
152 } // namespace bin 154 } // namespace bin
153 } // namespace dart 155 } // namespace dart
154 156
155 #endif // defined(TARGET_OS_WINDOWS) 157 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/utils_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698