diff options
| author | Tomasz Kramkowski <tk@the-tk.com> | 2018-04-21 21:11:32 +0200 | 
|---|---|---|
| committer | Tomasz Kramkowski <tk@the-tk.com> | 2018-04-21 21:11:32 +0200 | 
| commit | b0f260efed64e9db6b07bc36250971fc21a0f6db (patch) | |
| tree | cb928888983b0f7170efc5aefc190650ff54aaef | |
| parent | 7a802c4ff4c715f50825d833fa44f2ad1a5993f4 (diff) | |
| download | eprintf-master.tar.gz eprintf-master.tar.xz eprintf-master.zip | |
| -rw-r--r-- | eprintf.c | 26 | ||||
| -rw-r--r-- | eprintf.h | 3 | 
2 files changed, 29 insertions, 0 deletions
| @@ -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; +} @@ -7,10 +7,13 @@ noreturn void eprintf(const char *fmt, ...)  	__attribute__((format(printf, 1, 2)));  void weprintf(const char *fmt, ...)  	__attribute__((format(printf, 1, 2))); +void deprintf(const char *fmt, ...) +	__attribute__((format(printf, 1, 2)));  char *estrdup(const char *str);  void *emalloc(size_t size);  void *ecalloc(size_t nmemb, size_t size);  void *erealloc(void *p, size_t size);  void setprogname(const char *name); +void setdebug(int d);  #endif // !EPRINTF_EPRINTF_H | 
