From 7a91ea67a98c54fcdb9d1b092bba524200c726dd 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. --- tbdiff/tbdiff-common.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index 9e7fcd7..cbb5c0d 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -85,16 +86,42 @@ typedef enum { } tbd_error_e; #ifdef NDEBUG +#define TBD_DEBUG(d) +#define TBD_WARN(w) #define TBD_ERROR(e) (e) +#define TBD_DEBUGF(d, ...) +#define TBD_WARNF(w, ...) #else +#define TBD_DEBUG(d) \ + tbd_log("debug", "%s", __func__, __LINE__, __FILE__, d) +#define TBD_WARN(w) \ + tbd_log("warning", "%s", __func__, __LINE__, __FILE__, w) +#define TBD_DEBUGF(d, ...) \ + tbd_log("debug", d, __func__, __LINE__, __FILE__, __VA_ARGS__) +#define TBD_WARNF(w, ...) \ + tbd_log("warning", w, __func__, __LINE__, __FILE__, __VA_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