Mercurial > hg > th-libs
comparison th_config.c @ 708:a34715d51ea4
Add support for deallocator function in th_cfg_free() for freeing the values.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 Apr 2020 00:44:15 +0300 |
parents | ae601363fdad |
children | 4ca6a3b30fe8 |
comparison
equal
deleted
inserted
replaced
707:57d30f49fe1e | 708:a34715d51ea4 |
---|---|
13 | 13 |
14 | 14 |
15 #define SET_MAX_BUF (8192) | 15 #define SET_MAX_BUF (8192) |
16 | 16 |
17 | 17 |
18 /* Free a given configuration (the values are not free'd) | 18 /* Deallocate a given configuration. Notice that the values are NOT freed, |
19 */ | 19 * unless a deallocator function is specified to free them. |
20 void th_cfg_free(th_cfgitem_t *cfg) | 20 */ |
21 void th_cfg_free(th_cfgitem_t *cfg, void (*freefunc)(th_cfgitem_t *)) | |
21 { | 22 { |
22 th_cfgitem_t *node = cfg; | 23 th_cfgitem_t *node = cfg; |
23 | 24 |
24 while (node != NULL) | 25 while (node != NULL) |
25 { | 26 { |
26 th_cfgitem_t *next = (th_cfgitem_t *) node->node.next; | 27 th_cfgitem_t *next = (th_cfgitem_t *) node->node.next; |
27 | 28 |
28 if (node->type == ITEM_SECTION) | 29 if (node->type == ITEM_SECTION) |
29 th_cfg_free((th_cfgitem_t *) node->v.data); | 30 th_cfg_free((th_cfgitem_t *) node->v.data, freefunc); |
31 else | |
32 if (freefunc != NULL) | |
33 freefunc(node); | |
30 | 34 |
31 th_free(node->name); | 35 th_free(node->name); |
32 th_free(node); | 36 th_free(node); |
33 node = next; | 37 node = next; |
34 } | 38 } |