summaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-24 11:51:12 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-24 11:51:12 +0100
commit8e3274f153f89ecf1611fa8468d2d7dbe596a23f (patch)
treed53ed483e4714599826dab45a82574b9a5be2a11 /src/log
parent2f0a989a9ebd8d93fdcaf9a8530fea94877f607f (diff)
downloadwolfbones-8e3274f153f89ecf1611fa8468d2d7dbe596a23f.tar.gz
wolfbones-8e3274f153f89ecf1611fa8468d2d7dbe596a23f.tar.bz2
added strlcpy and strlcat (safe BSD C functions)
Diffstat (limited to 'src/log')
-rw-r--r--src/log/log.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/log/log.c b/src/log/log.c
index 28218d2..edbc00d 100644
--- a/src/log/log.c
+++ b/src/log/log.c
@@ -706,12 +706,17 @@ void wolf_log_reopenlogtoeventlog( void ) {
void wolf_log( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ) {
va_list ap;
- char s[1024];
va_start( ap, format );
- vsnprintf( s, 1024, format, ap );
+ wolf_log_ap( level, category_id, message_id, format, ap );
va_end( ap );
-
+}
+
+void wolf_log_ap( wolf_log_level_t level, int category_id, int message_id, const char *format, va_list ap ) {
+ char s[1024];
+
+ vsnprintf( s, 1024, format, ap );
+
if( level <= log_stderr_level )
fprintf( stderr, "%s: %s\n",wolf_log_level_to_str( level ), s );
@@ -746,13 +751,10 @@ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const ch
/* parse C-snprintf-like format string, map the placeholders
* there to normal strings, then add them to a string array
*/
- va_list ap;
int nof_placeholders = compute_nof_placeholders( format );
LPSTR *msg_arr = (LPSTR *)malloc( sizeof( LPCTSTR ) * nof_placeholders );
- va_start( ap, format );
map_placeholders_to_strings( msg_arr, format, ap );
- va_end( ap );
if( !ReportEvent(
event_source, /* event source handle */
@@ -776,3 +778,42 @@ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const ch
}
#endif /* defined HAVE_EVENTLOG */
}
+
+#if defined _WIN32
+
+void wolf_log_win32( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ) {
+ va_list ap;
+
+ va_start( ap, format );
+ wolf_log_win32_ap( level, category_id, message_id, format, ap );
+ va_end( ap );
+}
+
+void wolf_log_win32_ap( wolf_log_level_t level, int category_id, int message_id, const char *format, va_list ap ) {
+ DWORD last_error = GetLastError( );
+ LPVOID buf;
+ DWORD buf_size;
+ DWORD res;
+
+ res = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, /* message is from system */
+ last_error, /* there is a message with that id */
+ 0, /* default language preference */
+ (LPTSTR)&buf, /* buffer allocated internally with LocalAlloc */
+ 0, /* minimum allocation size */
+ NULL ); /* no arguments */
+
+ if( res == 0 ) {
+ /* FormatMessage failed, so log the error just with the
+ * GetLastError() number
+ */
+ char new_format[1024];
+
+
+ wolf_log_ap( level, category_id, message_id, new_format, ap );
+
+ }
+}
+#endif /* defined _WIN32 */