Index: runtime/bin/utils_win.cc |
diff --git a/runtime/bin/utils_win.cc b/runtime/bin/utils_win.cc |
index a3813f4b437b274d207b376e97904799ea8ff2fa..0dba5b5f7af60d343302de0ca3c8961c561d5fef 100644 |
--- a/runtime/bin/utils_win.cc |
+++ b/runtime/bin/utils_win.cc |
@@ -6,26 +6,42 @@ |
#include "bin/utils.h" |
-OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { |
- set_code(GetLastError()); |
- |
- static const int kMaxMessageLength = 256; |
- char message[kMaxMessageLength]; |
+static void FormatMessageIntoBuffer(DWORD code, |
+ char* buffer, |
+ int buffer_length) { |
DWORD message_size = |
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
NULL, |
- code_, |
+ code, |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
- message, |
- kMaxMessageLength, |
+ buffer, |
+ buffer_length, |
NULL); |
if (message_size == 0) { |
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { |
fprintf(stderr, "FormatMessage failed %d\n", GetLastError()); |
} |
- snprintf(message, kMaxMessageLength, "OS Error %d", code_); |
+ snprintf(buffer, buffer_length, "OS Error %d", code); |
} |
- message[kMaxMessageLength - 1] = '\0'; |
+ buffer[buffer_length - 1] = '\0'; |
+} |
+ |
+ |
+OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { |
+ set_code(GetLastError()); |
+ static const int kMaxMessageLength = 256; |
+ char message[kMaxMessageLength]; |
+ FormatMessageIntoBuffer(code_, message, kMaxMessageLength); |
+ SetMessage(message); |
+} |
+ |
+void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { |
+ set_sub_system(sub_system); |
+ set_code(code); |
+ |
+ static const int kMaxMessageLength = 256; |
+ char message[kMaxMessageLength]; |
+ FormatMessageIntoBuffer(code_, message, kMaxMessageLength); |
SetMessage(message); |
} |