util/Error: add method FormatLastError()

This commit is contained in:
Max Kellermann 2014-07-30 21:58:37 +02:00
parent d1bc46ffad
commit c8858f85d8
2 changed files with 32 additions and 0 deletions

View File

@ -145,4 +145,30 @@ Error::SetLastError(const char *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

View File

@ -168,6 +168,12 @@ public:
#ifdef WIN32
void SetLastError(DWORD _code, 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
};