diff options
author | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-05-29 14:54:12 +0100 |
---|---|---|
committer | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-05-29 18:00:43 +0100 |
commit | e7389e969c97eb949e5ee2e0e6dbb6fae943e100 (patch) | |
tree | 4f179134543d1b9a189d8dac4fa54a76a70e2885 | |
parent | fbdb7a0e12081c2eeb65e2fab1a9324aaa77466a (diff) | |
download | tbdiff-e7389e969c97eb949e5ee2e0e6dbb6fae943e100.tar.gz |
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
-rw-r--r-- | tbdiff/tbdiff-common.h | 25 |
1 files 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 <stdio.h> #include <stdint.h> +#include <stdarg.h> #include <tbdiff/tbdiff-stat.h> @@ -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 |