aboutsummaryrefslogtreecommitdiff
path: root/include/util.h
blob: 5279a07af333a38b9d7e0538f5d2d0d71f8ed9a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

#include <cjson/cJSON.h>

#define print_err(fmt, ...)                                                    \
	fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)

#define LIST_FOREACH_FREE(cur, next, head, field, func_free)                   \
	for ((cur) = ((head)->lh_first); (cur);) {                             \
		(next) = ((cur)->field.le_next);                               \
		func_free((cur));                                              \
		(cur) = (next);                                                \
	}

#define CIRCLEQ_FOREACH_FREE(cur, next, head, field, func_free)                \
	for ((cur) = ((head)->cqh_first); (cur) != (const void *)(head);) {    \
		(next) = ((cur)->field.cqe_next);                              \
		func_free((cur));                                              \
		(cur) = (next);                                                \
	}

int json_streaming_read(FILE *stream, cJSON **json);
int vpopen(FILE **stream, const char *file, char *const argv[]);