From 95a9726023abd85b49ed39837911e1b231f4389b Mon Sep 17 00:00:00 2001 From: katherine Date: Wed, 8 May 2019 23:33:41 -0700 Subject: implement internal tokeniser --- src/err.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/err.h (limited to 'src/err.h') diff --git a/src/err.h b/src/err.h new file mode 100644 index 0000000..3d3262f --- /dev/null +++ b/src/err.h @@ -0,0 +1,27 @@ +#ifndef CONFCONF_ERR_H +#define CONFCONF_ERR_H + +#include +#include + +#define ERR(...) \ + do { \ + fprintf(stderr, "error: " __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + exit(EXIT_FAILURE); \ + } while (0) + +#define TRY(cond, ...) \ + do { \ + if (!(cond)) { \ + ERR(__VA_ARGS__); \ + } \ + } while (0) + +#define TRYALLOC(dest, count) \ + do { \ + (dest) = malloc((count) * sizeof(*(dest))); \ + TRY((dest) != NULL, "could not allocate memory"); \ + } while (0) + +#endif -- cgit v1.2.3