aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/lib.h1
-rw-r--r--lib/llist.c16
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/lib.h b/lib/lib.h
index 0da3d9d6..b74cfbff 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -45,6 +45,7 @@ void llist_free_double(void *node);
void llist_traverse(void *list, void (*using)(void *node));
void *llist_pop(void *list); // actually void **list
void *dlist_pop(void *list); // actually struct double_list **list
+void *dlist_lpop(void *list); // also struct double_list **list
void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
struct double_list *dlist_add(struct double_list **list, char *data);
void *dlist_terminate(void *list);
diff --git a/lib/llist.c b/lib/llist.c
index 2969102d..e1e6a564 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -51,6 +51,7 @@ void *llist_pop(void *list)
return (void *)next;
}
+// Remove first item from &list and return it
void *dlist_pop(void *list)
{
struct double_list **pdlist = (struct double_list **)list, *dlist = *pdlist;
@@ -66,6 +67,21 @@ void *dlist_pop(void *list)
return dlist;
}
+// remove last item from &list and return it (stack pop)
+void *dlist_lpop(void *list)
+{
+ struct double_list *dl = *(struct double_list **)list;
+ void *v = 0;
+
+ if (dl) {
+ dl = dl->prev;
+ v = dlist_pop(&dl);
+ if (!dl) *(void **)list = 0;
+ }
+
+ return v;
+}
+
void dlist_add_nomalloc(struct double_list **list, struct double_list *new)
{
if (*list) {