diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-06-16 13:17:35 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-06-16 13:20:24 +0530 |
commit | d136b3c1b70d7ae687b763c59d1bc03d4ad3dbc2 (patch) | |
tree | cda33c21907a219fe18032f92b0bb8fedaf0c4d2 /include | |
parent | f407bbb1b00194fdc89ca382f4cf2f1f536ab18e (diff) |
c: improve memory management
Diffstat (limited to 'include')
-rw-r--r-- | include/util.h | 14 |
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[]); |