diff options
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 |