summaryrefslogtreecommitdiff
path: root/lib/linklist.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/linklist.c')
-rw-r--r--lib/linklist.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/linklist.c b/lib/linklist.c
index 4b16f07dd1..8b6a852826 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -159,6 +159,44 @@ listnode_add_after (struct list *list, struct listnode *pp, void *val)
list->count++;
}
+struct listnode *
+listnode_add_before (struct list *list, struct listnode *pp, void *val)
+{
+ struct listnode *nn;
+
+ assert (val != NULL);
+
+ nn = listnode_new ();
+ nn->data = val;
+
+ if (pp == NULL)
+ {
+ if (list->tail)
+ list->tail->next = nn;
+ else
+ list->head = nn;
+
+ nn->prev = list->tail;
+ nn->next = pp;
+
+ list->tail = nn;
+ }
+ else
+ {
+ if (pp->prev)
+ pp->prev->next = nn;
+ else
+ list->head = nn;
+
+ nn->prev = pp->prev;
+ nn->next = pp;
+
+ pp->prev = nn;
+ }
+ list->count++;
+ return nn;
+}
+
/* Move given listnode to tail of the list */
void
listnode_move_to_tail (struct list *l, struct listnode *n)