blob: 5a3b9bc8d14686478dc1253329732ba4b52af2cf (
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
28
29
30
31
32
33
34
35
36
37
38
39
|
#ifndef CONFCONF_ERR_H
#define CONFCONF_ERR_H
#include <stdio.h>
#include <stdlib.h>
#define ERR(...) \
do { \
fprintf(stderr, "\e[1;31merror:\e[0m " __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(EXIT_FAILURE); \
} while (0)
#define WARN(...) \
do { \
fprintf(stderr, "\e[1;35mwarning:\e[0m " __VA_ARGS__); \
fprintf(stderr, "\n"); \
} 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)
#define TRYREALLOC(dest, count) \
do { \
(dest) = realloc((dest), (count) * sizeof(*(dest))); \
TRY((dest) != NULL, "could not allocate memory"); \
} while (0)
#endif
|