]> jfr.im git - irc/atheme/libmowgli-2.git/commitdiff
Remove comma eating ## trick, isn't C99 compliant
authorPatrick McFarland <redacted>
Mon, 4 Feb 2013 09:12:56 +0000 (04:12 -0500)
committerPatrick McFarland <redacted>
Mon, 4 Feb 2013 09:14:18 +0000 (04:14 -0500)
src/libmowgli/core/logger.c
src/libmowgli/core/logger.h

index 7cd6bcea6eea841bd501ec752788ebce762139ed..76b5968e318fa6611220f6045627be9fea3fd93f 100644 (file)
@@ -30,7 +30,7 @@ void mowgli_log_cb_default(const char *buf)
 
 static mowgli_log_cb_t mowgli_log_cb = mowgli_log_cb_default;
 
-void mowgli_log_real(const char *file, int line, const char *func, const char *fmt, ...)
+void mowgli_log_real(const char *file, int line, const char *func, const char *prefix, const char *fmt, ...)
 {
        char buf[65535];
        char snbuf[65535];
@@ -40,7 +40,10 @@ void mowgli_log_real(const char *file, int line, const char *func, const char *f
        vsnprintf(snbuf, 65535, fmt, va);
        va_end(va);
 
-       snprintf(buf, 65535, "(%s:%d) [%s]: %s", file, line, func, snbuf);
+       if(prefix != NULL)
+               snprintf(buf, 65535, "(%s:%d) [%s]: %s: %s", file, line, func, prefix, snbuf);
+       else
+               snprintf(buf, 65535, "(%s:%d) [%s]: %s", file, line, func, snbuf);
 
        mowgli_log_cb(buf);
 }
index f4c24d6994465623d20e9cc18ef3a62b290ef3b9..db2cd02c8912abaed209755589b5ac16e016b211 100644 (file)
 
 typedef void (*mowgli_log_cb_t)(const char *);
 
-#define mowgli_log_warning(x, ...) mowgli_log("warning: #x", ##__VA_ARGS__);
+#define mowgli_log_warning(...) \
+       mowgli_log_prefix("warning: ", __VA_ARGS__)
 
-#define mowgli_log_error(x, ...) mowgli_log("error: #x", ##__VA_ARGS__)
+#define mowgli_log_error(...) \
+       mowgli_log_prefix("error: ", __VA_ARGS__)
 
-#define mowgli_log_fatal(x, ...) \
+#define mowgli_log_fatal(...) \
        do { \
-               mowgli_log("fatal: #x", ##__VA_ARGS__); \
+               mowgli_log_prefix("fatal: ", __VA_ARGS__); \
                abort(); \
        } while(0)
 
-#ifdef MOWGLI_COMPILER_GCC_COMPAT
-#define mowgli_log(...) mowgli_log_real(__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
+#if defined MOWGLI_COMPILER_GCC_COMPAT
+#define _FUNCARG __PRETTY_FUNCTION__
 #elif defined MOWGLI_COMPILER_MSVC
-#define mowgli_log(...) mowgli_log_real(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
+#define _FUNCARG __FUNCTION__
 #else
-#define mowgli_log(...) mowgli_log_real(__FILE__, __LINE__, __func__, __VA_ARGS__)
+#define _FUNCARG __func__
 #endif
 
-extern void mowgli_log_real(const char *file, int line, const char *func, const char *buf, ...);
+#define mowgli_log(...) \
+       mowgli_log_real(__FILE__, __LINE__, _FUNCARG, NULL, __VA_ARGS__);
+
+#define mowgli_log_prefix(prefix, ...) \
+       mowgli_log_real(__FILE__, __LINE__, _FUNCARG, prefix, __VA_ARGS__);
+
+extern void mowgli_log_real(const char *file, int line, const char *func, const char *prefix, const char *buf, ...);
 
 extern void mowgli_log_set_cb(mowgli_log_cb_t callback);