]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
ugly macros to make log_fn play nice on non-GCC compilers.
authorNick Mathewson <nickm@torproject.org>
Mon, 15 Nov 2004 21:18:07 +0000 (21:18 +0000)
committerNick Mathewson <nickm@torproject.org>
Mon, 15 Nov 2004 21:18:07 +0000 (21:18 +0000)
svn:r2894

src/common/log.c
src/common/log.h

index 500cfa1c1410ca44026f3d652d6ab66e276b7ea8..18676b8bf1695fdc17d7663ec110d4b3b1b53774 100644 (file)
@@ -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 <b>fn</b>. */
+#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()
index 2f90ce8c483d71752c3bbdab97597286c0d1b4f6..00eebd05c51f199ccb032cda1a83e3e62d34cff8 100644 (file)
@@ -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 */