From 36266228bb53550305e5fa3f43c03220a75f16cd Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Tue, 31 May 2011 15:50:56 +0200 Subject: Added functions freeitem() and delallitems(). --- list.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/list.c b/list.c index fcfe33f..d331e24 100644 --- a/list.c +++ b/list.c @@ -118,6 +118,49 @@ void delitem(struct item **mainlist, struct item *item) free(item); } +void freeitem(struct item **list, int *stored, + struct item *item) +{ + if (NULL == list || NULL == *list || NULL == item) + { + return; + } + + if (NULL != item->data) + { + free(item->data); + item->data = NULL; + } + + delitem(list, item); + + if (NULL != stored) + { + (*stored) --; + } +} + +/* + * Delete all elements in list and free memory resources. + */ +void delallitems(struct item **list, int *stored) +{ + struct item *item; + struct item *next; + + for (item = *list; item != NULL; item = next) + { + next = item->next; + free(item->data); + delitem(list, item); + } + + if (NULL != stored) + { + (*stored) = 0; + } +} + void listitems(struct item *mainlist) { struct item *item; -- cgit v1.2.3