# HG changeset patch # User Matti Hamalainen # Date 1423265831 -7200 # Node ID f9254c34ad052976664a4503eab57c9194d703eb # Parent 4cd94649475d12f478ec960f7667af0317b5643c Add new utility function for linked lists, th_llist_free_func_node(). diff -r 4cd94649475d -r f9254c34ad05 th_util.c --- a/th_util.c Sat Feb 07 00:19:43 2015 +0200 +++ b/th_util.c Sat Feb 07 01:37:11 2015 +0200 @@ -239,6 +239,20 @@ return res; } + +void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *)) +{ + th_llist_t *curr = list; + + while (curr != NULL) + { + th_llist_t *next = curr->next; + freefunc(curr); + curr = next; + } +} + + void th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data)) { th_llist_t *curr = list; @@ -246,7 +260,7 @@ while (curr != NULL) { th_llist_t *next = curr->next; - if (freefunc != NULL && curr->data != NULL) + if (curr->data != NULL) freefunc(curr->data); th_free(curr); curr = next; @@ -256,7 +270,14 @@ void th_llist_free(th_llist_t *list) { - th_llist_free_func(list, NULL); + th_llist_t *curr = list; + + while (curr != NULL) + { + th_llist_t *next = curr->next; + th_free(curr); + curr = next; + } } diff -r 4cd94649475d -r f9254c34ad05 th_util.h --- a/th_util.h Sat Feb 07 00:19:43 2015 +0200 +++ b/th_util.h Sat Feb 07 01:37:11 2015 +0200 @@ -155,6 +155,7 @@ th_llist_t * th_llist_new(void *data); void th_llist_free(th_llist_t *list); void th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data)); +void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *node)); void th_llist_append_node(th_llist_t **list, th_llist_t *node); th_llist_t * th_llist_append(th_llist_t **list, void *data);