From d5a0d432b679f0c4a8cc0a74d766ba03a008f7d9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 25 Mar 2009 10:05:49 +0100 Subject: fixed logger again, on Unix we stick to strerror_r+wolf_log (simple enough and doesn't introduce dependencies on variadic macros or similar stuff) --- include/wolf/log/log.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include') diff --git a/include/wolf/log/log.h b/include/wolf/log/log.h index b9f04b8..b31243b 100644 --- a/include/wolf/log/log.h +++ b/include/wolf/log/log.h @@ -19,6 +19,7 @@ #define WOLF_LOG_H #include "port/stdbool.h" +#include "port/gettext.h" /** * @addtogroup wolf_log Logging @@ -286,6 +287,34 @@ void wolf_log_reopenlogtoeventlog( void ); */ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ); +#ifdef _WIN32 +#define WOLF_LOG_GET_LAST_ERROR( errbuf, errbuf_size ) \ +{ \ + DWORD wolf_log_last_error = GetLastError( ); \ + LPVOID wolf_log_errbuf; \ + DWORD wolf_log_buf_size; \ + DWORD wolf_log_res; \ + \ + wolf_log_res = FormatMessage( \ + FORMAT_MESSAGE_ALLOCATE_BUFFER | \ + FORMAT_MESSAGE_FROM_SYSTEM | \ + FORMAT_MESSAGE_IGNORE_INSERTS | \ + FORMAT_MESSAGE_MAX_WIDTH_MASK, \ + NULL, /* message is from system */ \ + wolf_log_last_error, /* there is a message with that id */ \ + 0, /* default language preference */ \ + (LPTSTR)&wolf_log_errbuf,/* buffer allocated internally with LocalAlloc */\ + 0, /* minimum allocation size */ \ + NULL ); /* no arguments */ \ + \ + if( wolf_log_res == 0 ) { \ + strlcpy( wolf_log_errbuf, _( "No message available" ) \ + } \ + \ + strlcpy( errbuf, wolf_log_errbuf, errbuf_size ); \ +} +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.3-54-g00ecf