diff options
author | Michael Cardell Widerkrantz <mc@hack.org> | 2011-05-31 15:50:56 +0200 |
---|---|---|
committer | Michael Cardell Widerkrantz <mc@hack.org> | 2011-05-31 15:50:56 +0200 |
commit | 36266228bb53550305e5fa3f43c03220a75f16cd (patch) | |
tree | fcbf48e861baefec16f9785b178ac7cbd098d792 /list.c | |
parent | 14b7afc825c0ada766d5c5a0f48efd91ec9f771c (diff) | |
download | mcwm-36266228bb53550305e5fa3f43c03220a75f16cd.zip |
Added functions freeitem() and delallitems().
Diffstat (limited to 'list.c')
-rw-r--r-- | list.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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; |