summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-12-20 19:43:57 (GMT)
committerEvan Martin <martine@danga.com>2011-12-20 19:43:57 (GMT)
commit0cd066933511edb7869c5f6ce462b019a140ce3c (patch)
tree1fe70692438cf4c091a5fbfdcf0a9e832fba5f56
parent9bf145d98746d60d7d757ab6a8bc0c016d9c4360 (diff)
downloadNinja-0cd066933511edb7869c5f6ce462b019a140ce3c.zip
Ninja-0cd066933511edb7869c5f6ce462b019a140ce3c.tar.gz
Ninja-0cd066933511edb7869c5f6ce462b019a140ce3c.tar.bz2
factor out windows perror equivalent
-rw-r--r--src/subprocess-win32.cc16
-rw-r--r--src/util.cc21
-rw-r--r--src/util.h3
3 files changed, 25 insertions, 15 deletions
diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc
index 79c4eba..cf61feb 100644
--- a/src/subprocess-win32.cc
+++ b/src/subprocess-win32.cc
@@ -23,21 +23,7 @@
namespace {
void Win32Fatal(const char* function) {
- DWORD err = GetLastError();
-
- char* msg_buf;
- FormatMessageA(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (char*)&msg_buf,
- 0,
- NULL);
- Fatal("%s: %s", function, msg_buf);
- LocalFree(msg_buf);
+ Fatal("%s: %s", function, GetLastErrorString().c_str());
}
} // anonymous namespace
diff --git a/src/util.cc b/src/util.cc
index e8cd11e..0511806 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -210,3 +210,24 @@ const char* SpellcheckString(const string& text, ...) {
va_end(ap);
return result;
}
+
+#ifdef WIN32
+string GetLastErrorString() {
+ DWORD err = GetLastError();
+
+ char* msg_buf;
+ FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (char*)&msg_buf,
+ 0,
+ NULL);
+ string msg = msg_buf;
+ LocalFree(msg_buf);
+ return msg;
+}
+#endif
diff --git a/src/util.h b/src/util.h
index d36e2e1..f6601d3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -57,6 +57,9 @@ const char* SpellcheckString(const string& text, ...);
#ifdef _WIN32
#define snprintf _snprintf
+
+/// Convert the value returned by GetLastError() into a string.
+string GetLastErrorString();
#endif
#endif // NINJA_UTIL_H_