From 31a8f20fab6ba491503f685077c1a6b62de2db34 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 10 Dec 2022 12:58:01 -0800 Subject: macros: introduce some debug printing helpers Conditional on SARS_DEBUG defined (CFLAGS=-DSARS_DEBUG) This commit only adds the helpers, no actual users yet. --- src/macros.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/macros.h b/src/macros.h index 091af77..441a93b 100644 --- a/src/macros.h +++ b/src/macros.h @@ -20,6 +20,19 @@ #include #include +#ifdef SARS_DEBUG +#define debugf(_fmt, ...) \ + fprintf(stderr, "%s:%d: " _fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); +#else +#define debugf(_fmt, ...) \ + do { } while (0); +#endif + +#define debug_if(_cond, _fmt, ...) \ + if (_cond) { \ + debugf(_fmt, ##__VA_ARGS__); \ + } + #define fatal_if(_cond, _fmt, ...) \ if (_cond) { \ fprintf(stderr, "Fatal error: " _fmt "\n", ##__VA_ARGS__); \ -- cgit v1.2.3