diff options
-rw-r--r-- | include/wolf/log/log.h | 10 | ||||
-rw-r--r-- | tests/log/Makefile.W32 | 2 | ||||
-rw-r--r-- | tests/log/test_log.c | 20 | ||||
-rw-r--r-- | tests/log/testmsg.mc | 16 |
4 files changed, 41 insertions, 7 deletions
diff --git a/include/wolf/log/log.h b/include/wolf/log/log.h index b31243b..ae91de2 100644 --- a/include/wolf/log/log.h +++ b/include/wolf/log/log.h @@ -288,9 +288,9 @@ 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 ) \ + +#define WOLF_LOG_GET_LAST_ERROR( last_error, errbuf, errbuf_size ) \ { \ - DWORD wolf_log_last_error = GetLastError( ); \ LPVOID wolf_log_errbuf; \ DWORD wolf_log_buf_size; \ DWORD wolf_log_res; \ @@ -301,14 +301,14 @@ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const ch 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 */ \ + last_error, /* there is a message with that id */ \ 0, /* default language preference */ \ - (LPTSTR)&wolf_log_errbuf,/* buffer allocated internally with LocalAlloc */\ + (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, _( "No message available" ), errbuf_size ); \ } \ \ strlcpy( errbuf, wolf_log_errbuf, errbuf_size ); \ diff --git a/tests/log/Makefile.W32 b/tests/log/Makefile.W32 index f7d5a69..a7f7be7 100644 --- a/tests/log/Makefile.W32 +++ b/tests/log/Makefile.W32 @@ -11,7 +11,7 @@ INCLUDE_LDFLAGS = \ INCLUDE_LIBS = \ $(TOPDIR)\src\wolf.lib \ - advapi32.lib + advapi32.lib kernel32.lib LIBRARIES = \ testmsg.dll diff --git a/tests/log/test_log.c b/tests/log/test_log.c index b3cca7b..687775c 100644 --- a/tests/log/test_log.c +++ b/tests/log/test_log.c @@ -5,6 +5,11 @@ #include <stdlib.h> /* for exit, EXIT_SUCCESS, free */ #include <errno.h> /* for errno */ +#if _WIN32 +#define WIND32_LEAN_AND_MEAN +#include <windows.h> +#endif + #define WOLF_CATEGORY_TEST_LOG WOLF_LAST_INTERNAL_CATEGORY+1 #define WOLF_MSG_TEST_LOG_BASE ( WOLF_CATEGORY_TEST_LOG ) * 1000 @@ -15,9 +20,13 @@ #define WOLF_MSG_TEST_LOG_MSG5 WOLF_MSG_TEST_LOG_BASE+5 #define WOLF_MSG_TEST_LOG_MSG6 WOLF_MSG_TEST_LOG_BASE+6 #define WOLF_MSG_TEST_LOG_MSG7 WOLF_MSG_TEST_LOG_BASE+7 +#define WOLF_MSG_TEST_LOG_MSG8 WOLF_MSG_TEST_LOG_BASE+8 int main( void ) { char errbuf[512]; +#ifdef _WIN32 + DWORD last_error; +#endif wolf_log_openlogtostderr( WOLF_LOG_NOTICE ); wolf_log_openlogtofile( "test.log", WOLF_LOG_NOTICE ); @@ -47,7 +56,16 @@ int main( void ) { errno = 5; (void)strerror_r( errno, errbuf, 512 ); wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG7, - "A system error occured during %s phase: %s (%d)", "fla", errbuf, errno ); + "A system error occured during %s phase: %s (%d)", "fla", + errbuf, errno ); + +#ifdef _WIN32 + SetLastError( 18 ); + WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); + wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG8, + "A Windows error occured during %s phase: %s (%d)", "fla", + errbuf, GetLastError( ) ); +#endif #if defined WOLF_LOG_HAVE_EVENTLOG wolf_log_closelogtoeventlog( ); diff --git a/tests/log/testmsg.mc b/tests/log/testmsg.mc index 658aad0..4deb4d9 100644 --- a/tests/log/testmsg.mc +++ b/tests/log/testmsg.mc @@ -99,3 +99,19 @@ SymbolicName = WOLF_MSG_TEST_LOG_MSG6 Language = English This is error %1 with %2 . + +MessageId = 3007 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TEST_LOG_MSG7 +Language = English +A system error occured during %1 phase: %2 (%3) +. + +MessageId = 3008 +Severity = Error +Facility = Application +SymbolicName = WOLF_MSG_TEST_LOG_MSG8 +Language = English +A Windows error occured during %1 phase: %2 (%3) +. |