summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brewer <ben.brewer@codethink.co.uk>2014-05-29 13:54:12 (GMT)
committerBen Brewer <ben.brewer@codethink.co.uk>2014-06-02 10:03:00 (GMT)
commit7a91ea67a98c54fcdb9d1b092bba524200c726dd (patch)
treef38a210d3b325cb17d51c64eefd38011f90397ce
parente39253f8632c83c289ab118e044175950d8e902e (diff)
downloadtbdiff-7a91ea67a98c54fcdb9d1b092bba524200c726dd.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.
-rw-r--r--tbdiff/tbdiff-common.h31
1 files 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 <stdio.h>
#include <stdint.h>
+#include <stdarg.h>
#include <tbdiff/tbdiff-stat.h>
@@ -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