From b0f260efed64e9db6b07bc36250971fc21a0f6db Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 21 Apr 2018 21:11:32 +0200 Subject: add deprintf function --- eprintf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'eprintf.c') diff --git a/eprintf.c b/eprintf.c index 9f4aa11..d1cde98 100644 --- a/eprintf.c +++ b/eprintf.c @@ -9,6 +9,7 @@ #include "eprintf.h" static char *pname; +static int debug = 0; // doprintf: print error message __attribute__((format(printf, 1, 0))) @@ -48,6 +49,25 @@ void weprintf(const char *fmt, ...) va_end(va); } +// deprintf: print debug message if debugging is enabled +void deprintf(const char *fmt, ...) +{ + va_list va; + + assert(fmt != NULL); + + if (!debug) + return; + + if (pname != NULL) + fprintf(stderr, "%s: ", pname); + + fputs("debug: ", stderr); + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); +} + // estrdup: attempt to strdup a string or exit on error char *estrdup(const char *s) { @@ -115,3 +135,9 @@ void setprogname(const char *s) pname = estrdup(s); } + +// setdebug: set debug +void setdebug(int d) +{ + debug = d; +} -- cgit v1.2.3-54-g00ecf