diff options
author | katherine <shmibs@airen-no-jikken.icu> | 2019-05-08 23:33:41 -0700 |
---|---|---|
committer | katherine <shmibs@airen-no-jikken.icu> | 2019-05-08 23:33:41 -0700 |
commit | 95a9726023abd85b49ed39837911e1b231f4389b (patch) | |
tree | 3535a3ca1feac910ecf736fdc07ddcb5559f4321 /src/err.h | |
parent | ca0d95e26663e05d702c6f3a5627812dbf0c9f90 (diff) | |
download | confconf-95a9726023abd85b49ed39837911e1b231f4389b.tar.gz |
implement internal tokeniser
Diffstat (limited to 'src/err.h')
-rw-r--r-- | src/err.h | 27 |
1 files changed, 27 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +#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 |