diff options
author | Evan Martin <martine@danga.com> | 2011-12-20 19:43:57 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-12-20 19:43:57 (GMT) |
commit | 0cd066933511edb7869c5f6ce462b019a140ce3c (patch) | |
tree | 1fe70692438cf4c091a5fbfdcf0a9e832fba5f56 /src | |
parent | 9bf145d98746d60d7d757ab6a8bc0c016d9c4360 (diff) | |
download | Ninja-0cd066933511edb7869c5f6ce462b019a140ce3c.zip Ninja-0cd066933511edb7869c5f6ce462b019a140ce3c.tar.gz Ninja-0cd066933511edb7869c5f6ce462b019a140ce3c.tar.bz2 |
factor out windows perror equivalent
Diffstat (limited to 'src')
-rw-r--r-- | src/subprocess-win32.cc | 16 | ||||
-rw-r--r-- | src/util.cc | 21 | ||||
-rw-r--r-- | src/util.h | 3 |
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 @@ -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_ |