summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2011-05-31 15:50:56 +0200
committerMichael Cardell Widerkrantz <mc@hack.org>2011-05-31 15:50:56 +0200
commit36266228bb53550305e5fa3f43c03220a75f16cd (patch)
treefcbf48e861baefec16f9785b178ac7cbd098d792
parent14b7afc825c0ada766d5c5a0f48efd91ec9f771c (diff)
downloadmcwm-36266228bb53550305e5fa3f43c03220a75f16cd.zip
Added functions freeitem() and delallitems().
-rw-r--r--list.c43
1 files changed, 43 insertions, 0 deletions
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;