summaryrefslogtreecommitdiffstats
path: root/dlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'dlink.c')
-rw-r--r--dlink.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/dlink.c b/dlink.c
index 69aa7aa..3463367 100644
--- a/dlink.c
+++ b/dlink.c
@@ -26,6 +26,21 @@ void dl_free(void *v)
free(vv-1);
}
+void dl_free_all(void *head)
+{
+ /* The list head is linked with the list tail so in order to free
+ * all the elements properly there is a need to keep starting point.
+ */
+ void *d = dl_next(head), *next;
+
+ while (d != head) {
+ next = dl_next(d);
+ dl_free(d);
+ d = next;
+ }
+ dl_free(head);
+}
+
void dl_init(void *v)
{
dl_next(v) = v;