aboutsummaryrefslogtreecommitdiffstats
path: root/src/err.h
blob: 3d3262fcf87d130a44d113eb244a9c8b09ddf1ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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