summaryrefslogtreecommitdiff
path: root/src/debug.h
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-07-21 22:29:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-08-13 22:56:32 -0700
commit870e63be7360b5a0097a27656048e853bc720464 (patch)
treee8f19ee2d62e529115cb71dcda5f3298cca7d389 /src/debug.h
parent650ad87f35f4405a2ca8270d2b2835daa442e5f1 (diff)
Initial commit
Diffstat (limited to 'src/debug.h')
-rw-r--r--src/debug.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/debug.h b/src/debug.h
new file mode 100644
index 0000000..af1d017
--- /dev/null
+++ b/src/debug.h
@@ -0,0 +1,36 @@
+#ifndef __debug_h__
+#define __debug_h__
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#ifdef NDEBUG
+#define debug(M, ...)
+#else
+#define debug(M, ...) \
+ fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
+#endif
+
+#define clean_errno() (errno == 0 ? "None" : strerror(errno))
+
+#define log_err(M, ...) \
+ fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
+ clean_errno(), ##__VA_ARGS__)
+
+#define log_warn(M, ...) \
+ fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
+ clean_errno(), ##__VA_ARGS__)
+
+#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, \
+ __LINE__, ##__VA_ARGS__)
+
+#define check(A, M, ...) \
+ if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
+
+#define sentinel(M, ...) \
+ { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
+
+#define check_debug(A, M, ...) \
+ if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
+
+#endif