From f2e92179780ad5611d6b040b241dda75adc68428 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 15 Feb 2015 12:23:56 +0100 Subject: [PATCH] Add debug function/macro, derived from warn --- common/util.c | 13 +++++++++++++ common/util.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/common/util.c b/common/util.c index 267fd559d..a88c30764 100644 --- a/common/util.c +++ b/common/util.c @@ -73,6 +73,19 @@ _warn(int line, const char *fct, const char *fmt, ...) fprintf(stderr, "\n"); } +/** Print debug message on stderr. + */ +void +_debug(int line, const char *fct, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(stderr, "D: awesome: %s:%d: ", fct, line); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); +} + /** \brief safe limited strcpy. * * Copies at most min(n-1, \c l) characters from \c src into \c dst, diff --git a/common/util.h b/common/util.h index eaa9a58de..8111799a1 100644 --- a/common/util.h +++ b/common/util.h @@ -321,6 +321,12 @@ void _warn(int, const char *, const char *, ...) const char *a_current_time_str(void); +#define debug(string, ...) _debug(__LINE__, \ + __FUNCTION__, \ + string, ## __VA_ARGS__) +void _debug(int, const char *, const char *, ...) + __attribute__ ((format(printf, 3, 4))); + void a_exec(const char *); #endif