From e7389e969c97eb949e5ee2e0e6dbb6fae943e100 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 14:54:12 +0100 Subject: Added warning and debug mechanism to tbdiff-common.h Added TBD_WARN and TBD_DEBUG macros to allow for warnings and debug messages to be printed. This will make current debugging messages cleaner and allow us to warn when the chown operation fails. blah warning log debug --- tbdiff/tbdiff-common.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index 9e7fcd7..de3f5f9 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -85,16 +86,36 @@ typedef enum { } tbd_error_e; #ifdef NDEBUG +#define TBD_DEBUG(d...) +#define TBD_WARN(w...) #define TBD_ERROR(e) (e) #else +#define TBD_DEBUG(d, args...) \ + tbd_log("debug", d, __func__, __LINE__, __FILE__ , ##args) +#define TBD_WARN(w, args...) \ + tbd_log("warning", w, __func__, __LINE__, __FILE__ , ##args) +static inline +tbd_log(char const *t, char const *s, char const *func, int line, + char const *file, ...) +{ + va_list args; + va_start(args, file); + + fprintf(stderr, "TBDiff %s '", t); + vfprintf(stderr, s, args); + fprintf(stderr, "' in function '%s' at line %d of file '%s'.\n", + func, line, file); + + va_end(args); +} + #define TBD_ERROR(e) tbd_error(e, #e, __func__, __LINE__, __FILE__) static inline tbd_error_e tbd_error(tbd_error_e e, char const *s, char const *func, int line, char const* file) { if (e != TBD_ERROR_SUCCESS) - fprintf(stderr, "TBDiff error '%s' in function '%s' at line %d " - "of file '%s'.\n", s, func, line, file); + tbd_log("error", "%s", func, line, file, s); return e; } #endif -- cgit v1.2.1