Commit c8858f85 authored by Max Kellermann's avatar Max Kellermann

util/Error: add method FormatLastError()

parent d1bc46ff
...@@ -145,4 +145,30 @@ Error::SetLastError(const char *prefix) ...@@ -145,4 +145,30 @@ Error::SetLastError(const char *prefix)
SetLastError(GetLastError(), prefix); SetLastError(GetLastError(), prefix);
} }
void
Error::FormatLastError(DWORD _code, const char *fmt, ...)
{
char buffer[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
SetLastError(_code, buffer);
}
void
Error::FormatLastError(const char *fmt, ...)
{
DWORD _code = GetLastError();
char buffer[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
SetLastError(_code, buffer);
}
#endif #endif
...@@ -168,6 +168,12 @@ public: ...@@ -168,6 +168,12 @@ public:
#ifdef WIN32 #ifdef WIN32
void SetLastError(DWORD _code, const char *prefix); void SetLastError(DWORD _code, const char *prefix);
void SetLastError(const char *prefix); void SetLastError(const char *prefix);
gcc_printf(3,4)
void FormatLastError(DWORD code, const char *fmt, ...);
gcc_printf(2,3)
void FormatLastError(const char *fmt, ...);
#endif #endif
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment