aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-06-16 13:17:35 +0530
committersinanmohd <sinan@sinanmohd.com>2024-06-16 13:20:24 +0530
commitd136b3c1b70d7ae687b763c59d1bc03d4ad3dbc2 (patch)
treecda33c21907a219fe18032f92b0bb8fedaf0c4d2 /include
parentf407bbb1b00194fdc89ca382f4cf2f1f536ab18e (diff)
c: improve memory management
Diffstat (limited to 'include')
-rw-r--r--include/util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h
index c5aa0ab..5279a07 100644
--- a/include/util.h
+++ b/include/util.h
@@ -5,5 +5,19 @@
#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[]);