diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-24 19:20:54 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-24 19:20:54 +0100 |
commit | fd07459ba8f06ac8674d3c16c16dd41f00aa492e (patch) | |
tree | 66b437ee848fde408a82223ed308a5b89cb84b82 /src/log | |
parent | 27cbbcc79bdf376a4c761594de6fd44a28530f91 (diff) | |
download | wolfbones-fd07459ba8f06ac8674d3c16c16dd41f00aa492e.tar.gz wolfbones-fd07459ba8f06ac8674d3c16c16dd41f00aa492e.tar.bz2 |
added wolf_log_strerror and fixed itoa prototype
Diffstat (limited to 'src/log')
-rw-r--r-- | src/log/log.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/log/log.c b/src/log/log.c index 56001a1..d8b7e20 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -24,6 +24,7 @@ strlcat */ #include "port/time.h" /* for localtime_r, strftime, time * time_t, struct tm */ +#include "port/stdlib.h" /* for abort, itoa */ #include "port/unused.h" /* for WOLF_UNUSED */ #define DEFAULT_TEXT_DOMAIN "libwolf" #include "port/gettext.h" /* for i18n */ @@ -31,7 +32,6 @@ #include <stdarg.h> /* for variable arguments */ #include <errno.h> /* for errno */ #include <assert.h> /* for assertions */ -#include <stdlib.h> /* for abort */ #if defined HAVE_SYSLOG_H #include <syslog.h> /* for syslog, closelog and levels */ @@ -823,4 +823,31 @@ void wolf_log_win32_ap( wolf_log_level_t level, int category_id, int message_id, wolf_log_ap( level, category_id, message_id, new_format, ap ); } + #endif /* defined _WIN32 */ + +void wolf_log_strerror( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ) { + va_list ap; + + va_start( ap, format ); + wolf_log_strerror_ap( level, category_id, message_id, format, ap ); + va_end( ap ); +} + +void wolf_log_strerror_ap( wolf_log_level_t level, int category_id, int message_id, const char *format, va_list ap ) { + int error_no = errno; + char errbuf[512]; + char new_format[1024]; + char int_buf[20]; + + (void)strerror_r( error_no, errbuf, 1024 ); + + strlcpy( new_format, format, 1024 ); + strlcat( new_format, ": ", 1024 ); + strlcat( new_format, errbuf, 1024 ); + strlcat( new_format, " (", 1024 ); + strlcat( new_format, itoa( error_no, int_buf, 10 ), 1024 ); + strlcat( new_format, ")", 1024 ); + + wolf_log_ap( level, category_id, message_id, new_format, ap ); +} |