aboutsummaryrefslogtreecommitdiffstats
path: root/src/err.h
diff options
context:
space:
mode:
authorkatherine <shmibs@airen-no-jikken.icu>2019-05-08 23:33:41 -0700
committerkatherine <shmibs@airen-no-jikken.icu>2019-05-08 23:33:41 -0700
commit95a9726023abd85b49ed39837911e1b231f4389b (patch)
tree3535a3ca1feac910ecf736fdc07ddcb5559f4321 /src/err.h
parentca0d95e26663e05d702c6f3a5627812dbf0c9f90 (diff)
downloadconfconf-95a9726023abd85b49ed39837911e1b231f4389b.tar.gz
implement internal tokeniser
Diffstat (limited to 'src/err.h')
-rw-r--r--src/err.h27
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