aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-12-05 08:52:50 +0100
committerTharre <tharre3@gmail.com>2014-12-05 08:52:50 +0100
commitb8ffd5621f5495b0ad1a92a67b51b7e0e15b0b6e (patch)
tree991917a3be44acfed12922162f7f7443f4d919f7
parent622bdcb7e36498b2bfdc193b00cf690a6a11512b (diff)
downloadredo-b8ffd5621f5495b0ad1a92a67b51b7e0e15b0b6e.tar.gz
redo-b8ffd5621f5495b0ad1a92a67b51b7e0e15b0b6e.tar.xz
redo-b8ffd5621f5495b0ad1a92a67b51b7e0e15b0b6e.zip
Improve error message handling for debugging
-rw-r--r--src/dbg.h15
-rw-r--r--src/util.c2
-rw-r--r--src/util.h5
3 files changed, 14 insertions, 8 deletions
diff --git a/src/dbg.h b/src/dbg.h
index ef86cac..961128f 100644
--- a/src/dbg.h
+++ b/src/dbg.h
@@ -21,7 +21,18 @@
/* helper functions which help in replacing the GNU extension ##__VA_ARGS__ */
#define STRINGIFY(x) #x
-#define LOG_HELPER(f,l,...) fprintf(stderr, "("f":"STRINGIFY(l)"): "__VA_ARGS__)
+#define PREFIX(...) PREFIX_HELPER(_FILENAME, __LINE__, __VA_ARGS__)
+#define SUFFIX(S, M, ...) M S, __VA_ARGS__
+
+#define log_err(...) fprintf(stderr, PREFIX(__VA_ARGS__))
+#define die(...) die_(PREFIX(__VA_ARGS__))
+#define fatal(...) die(SUFFIX(": %s\n", __VA_ARGS__, strerror(errno)))
+
+#ifdef NDEBUG
+#define PREFIX_HELPER(f,l,...) __VA_ARGS__
+#else
+#define PREFIX_HELPER(f,l,...) "(" f ":" STRINGIFY(l) "): " __VA_ARGS__
+#endif
#ifdef NDEBUG
#define debug(...)
@@ -29,8 +40,6 @@
#define debug(...) log_err(__VA_ARGS__)
#endif
-#define log_err(...) LOG_HELPER(_FILENAME, __LINE__, __VA_ARGS__)
-
#define assert_str_equal(a,b) ({ \
if (strcmp(a, b)) { \
log_err("Assertion error: '%s' == '%s'\n", a, b); \
diff --git a/src/util.c b/src/util.c
index a871588..bd7e0bf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -21,7 +21,7 @@
/* Print a given formated error message and die. */
-extern void __attribute__((noreturn)) die(const char *err, ...) {
+extern void __attribute__((noreturn)) die_(const char *err, ...) {
assert(err);
va_list ap;
va_start(ap, err);
diff --git a/src/util.h b/src/util.h
index db02cd4..5e46166 100644
--- a/src/util.h
+++ b/src/util.h
@@ -11,10 +11,7 @@
#include <stddef.h>
-#define DIE_HELPER(M, ...) die(M ": %s\n", __VA_ARGS__)
-#define fatal(...) DIE_HELPER(__VA_ARGS__, strerror(errno))
-
-extern void __attribute__((noreturn)) die(const char *err, ...);
+extern void __attribute__((noreturn)) die_(const char *err, ...);
extern void *xmalloc(size_t size);
extern void *xrealloc(void *ptr, size_t size);
extern char *xstrdup(const char *str);