aboutsummaryrefslogtreecommitdiff
path: root/lib/llist.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-07-10 01:53:23 -0500
committerRob Landley <rob@landley.net>2019-07-10 01:53:23 -0500
commitc3ccbbc4ff3352877ed39b6d4fa430affea0e9a4 (patch)
tree13db6e3a501a83f151b60102ef51ab02242e4666 /lib/llist.c
parent4c6f35ea529ebca9b2dfb6d7c79cade30118fd75 (diff)
downloadtoybox-c3ccbbc4ff3352877ed39b6d4fa430affea0e9a4.tar.gz
Add dlist_lpop() to remove last entry (use dlist as stack).
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c16
1 files changed, 16 insertions, 0 deletions
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) {