diff options
| author | mikeos <mike.osipov@gmail.com> | 2012-10-13 23:20:14 +0400 |
|---|---|---|
| committer | mikeos <mike.osipov@gmail.com> | 2012-10-13 23:20:14 +0400 |
| commit | 893c216b889f260378fb21a7f576c061f7ff2248 (patch) | |
| tree | ad4566df268c76de8fc743d006b14baf6bfb6594 /debug.h | |
initial
Diffstat (limited to 'debug.h')
| -rw-r--r-- | debug.h | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +#ifndef __DEBUG_H +#define __DEBUG_H + +#include <stdio.h> +#include <errno.h> + +#ifndef NOCOLOR +#define GREEN "[32m" +#define DEF "[0m" +#define RED "[31m" +#else +#define GREEN +#define DEF +#define RED +#endif + +#ifndef NDEBUG +#define DEBUG_CODE(code) \ +do { \ + code; \ +} while (0) +#else +#define DEBUG_CODE(code) +#endif + +#define PROMPT_FMT(fmt) GREEN "%s" DEF ":" GREEN "%d" DEF ": " fmt + +#define msg_err(fmt, args...) \ + fprintf(stderr, PROMPT_FMT(fmt) ": " \ + RED "%s" DEF "\n", \ + __FILE__, __LINE__, ## args, strerror(errno)) + +#define msg_warn(fmt, args...) \ + fprintf(stderr, PROMPT_FMT(fmt) "\n", \ + __FILE__, __LINE__, ## args) + +#define sys_err(fmt, args...) \ +do { \ + msg_err(fmt, ## args); \ + exit(1); \ +} while (0) + +#define err_quit(fmt, args...) \ +do { \ + msg_warn(fmt, ## args); \ + exit(1); \ +} while (0) + +#endif |
