From 5b668d855767a9331fb60c06708d58ed3ef5ffb1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 15 Nov 2004 21:18:07 +0000 Subject: [PATCH] ugly macros to make log_fn play nice on non-GCC compilers. svn:r2894 --- src/common/log.c | 13 +++++++++++++ src/common/log.h | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/common/log.c b/src/common/log.c index 500cfa1c14..18676b8bf1 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -203,7 +203,9 @@ void _log(int severity, const char *format, ...) va_end(ap); } + /** Output a message to the log, prefixed with a function name fn. */ +#ifdef __GNUC__ void _log_fn(int severity, const char *fn, const char *format, ...) { va_list ap; @@ -211,6 +213,17 @@ void _log_fn(int severity, const char *fn, const char *format, ...) logv(severity, fn, format, ap); va_end(ap); } +#else +const char *_log_fn_function_name=NULL; +void _log_fn(int severity, const char *format, ...) +{ + va_list ap; + va_start(ap,format); + logv(severity, _log_fn_function_name, format, ap); + va_end(ap); + _log_fn_function_name = NULL; +} +#endif /** Close all open log files. */ void close_logs() diff --git a/src/common/log.h b/src/common/log.h index 2f90ce8c48..00eebd05c5 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -81,7 +81,14 @@ void _log_fn(int severity, const char *funcname, const char *format, ...) #define log_fn(severity, args...) \ _log_fn(severity, __PRETTY_FUNCTION__, args) #else -#define log_fn _log +/* We don't have GCC's varargs macros, so use a global variable to pass the + * function name to log_fn */ +extern const char *_log_fn_function_name; +void _log_fn(int severity, const char *format, ...); +/* We abuse the comma operator here, since we can't use the standard + * do {...} while(0) trick to wrap this macro, since the macro can't take + * arguments. */ +#define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn #endif #define log _log /* hack it so we don't conflict with log() as much */ -- 2.47.3