From 08bf4f74a99cb542a20e18b896b8565f6bf1f37a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Dec 2014 00:16:24 +0100 Subject: system/FatalError: add FatalSystemError() overload with WIN32 error code --- src/system/FatalError.cxx | 28 ++++++++++++++++++---------- src/system/FatalError.hxx | 12 ++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/system/FatalError.cxx b/src/system/FatalError.cxx index a2d06bcb1..cb5d7160a 100644 --- a/src/system/FatalError.cxx +++ b/src/system/FatalError.cxx @@ -74,23 +74,31 @@ FatalError(const char *msg, const Error &error) FormatFatalError("%s: %s", msg, error.GetMessage()); } +#ifdef WIN32 + +void +FatalSystemError(const char *msg, DWORD code) +{ + char buffer[256]; + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, code, 0, + buffer, sizeof(buffer), nullptr); + FormatFatalError("%s: %s", msg, buffer); +} + +#endif + void FatalSystemError(const char *msg) { - const char *system_error; #ifdef WIN32 - char buffer[256]; - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, GetLastError(), 0, - buffer, sizeof(buffer), nullptr); - system_error = buffer; + FatalSystemError(msg, GetLastError()); #else - system_error = strerror(errno); -#endif - + const char *system_error = strerror(errno); FormatError(fatal_error_domain, "%s: %s", msg, system_error); Abort(); +#endif } void diff --git a/src/system/FatalError.hxx b/src/system/FatalError.hxx index d4698b3d9..2cf693bc3 100644 --- a/src/system/FatalError.hxx +++ b/src/system/FatalError.hxx @@ -23,6 +23,10 @@ #include "check.h" #include "Compiler.h" +#ifdef WIN32 +#include +#endif + class Error; /** @@ -53,6 +57,14 @@ gcc_noreturn void FatalSystemError(const char *msg); +#ifdef WIN32 + +gcc_noreturn +void +FatalSystemError(const char *msg, DWORD code); + +#endif + gcc_noreturn void FormatFatalSystemError(const char *fmt, ...); -- cgit v1.2.3