From 3b381609dddb8f4f9c3668681e4e475501b3f38f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 23 May 2010 11:45:32 +0200 Subject: removed FormatMessage/Win32 macro from log.h and added a more portable wolf_system_error_msg in errors module --- include/wolf/errors.h | 13 +++++++++++++ include/wolf/library/loader.h | 2 +- include/wolf/log/log.h | 28 ---------------------------- 3 files changed, 14 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/wolf/errors.h b/include/wolf/errors.h index 96b6e2f..c33d619 100644 --- a/include/wolf/errors.h +++ b/include/wolf/errors.h @@ -60,6 +60,19 @@ typedef enum { */ char *wolf_error_msg( const wolf_error_t error, char *buf, size_t buflen ); +/** + * Converts the last system error into a human readable message. + * On Windows this is done with FormatMessage and GetLastError, on + * Unix with strerror_r and errno. + * + * @param error the error to retrieve the textual representation for + * @param buf the buffer which will hold the error message + * @param buflen the size of the buffer + * + * @returns a pointer to buf for convenience + */ +char *wolf_system_error_msg( char *buf, size_t buflen ); + #ifdef __cplusplus } #endif diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h index 437fa1b..b62b350 100644 --- a/include/wolf/library/loader.h +++ b/include/wolf/library/loader.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2010 Andreas Baumann + Copyright (C) 2008 Andreas Baumann This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/include/wolf/log/log.h b/include/wolf/log/log.h index 78e2b63..e8f1878 100644 --- a/include/wolf/log/log.h +++ b/include/wolf/log/log.h @@ -288,34 +288,6 @@ 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( last_error, errbuf, errbuf_size ) \ -{ \ - 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 */ \ - 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( errbuf, _( "No message available" ), errbuf_size ); \ - } \ - \ - strlcpy( errbuf, wolf_log_errbuf, errbuf_size ); \ -} -#endif - #ifdef __cplusplus } #endif -- cgit v1.2.3-54-g00ecf