diff options
Diffstat (limited to 'main.h')
-rw-r--r-- | main.h | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -27,17 +27,26 @@ debug_enabled(enum debug_category category) return !!(category & debug_mask); } -void do_debug(enum debug_category category, const char *fmt, ...); - -#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0) -#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__) -#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__) -#define info(...) __debug(DBG_ERROR, __VA_ARGS__) -#define error(...) __debug(DBG_ERROR, __VA_ARGS__) - -void die(const char *fmt, ...); - -#define perrordie(msg) die("%s: %m\n", msg) +void __debug(enum debug_category category, const char *fmt, ...) __attribute__((format(printf, 2, 3))); + +#define __ifdebug(c, fmt, ...) \ + do { \ + if (debug_enabled((c))) \ + __debug((c), fmt __VA_OPT__(,) __VA_ARGS__); \ + } while (0) + +#define debug(c, fmt, ...) __ifdebug((c), "%s:%i: " fmt, __func__, \ + __LINE__, __VA_ARGS__) +#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__) +#define info(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__) +#define error(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__) + +void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2))); + +#define die(fmt, ...) __die("%s:%i: " fmt "\n", __func__, \ + __LINE__ __VA_OPT__(,) __VA_ARGS__) +#define perrordie(fmt, ...) __die("%s:%i: " fmt ": %m\n", __func__, \ + __LINE__ __VA_OPT__(,) __VA_ARGS__) struct uring_task; |