summaryrefslogtreecommitdiff
path: root/lib/linklist.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-05-28 10:15:09 -0300
committerRenato Westphal <renato@opensourcerouting.org>2018-08-13 18:59:31 -0300
commit9ea82f28d499f2bf5668fde86474b3e5287e58c6 (patch)
tree477b4f8d87db2932d745af59a69cba33d8a6e7f4 /lib/linklist.c
parent27982ebc9d211a9353029a043a120fdf291f5171 (diff)
lib: add listnode_add_head()
Provide a new convenience function that adds an element to the beginning of a list. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/linklist.c')
-rw-r--r--lib/linklist.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/linklist.c b/lib/linklist.c
index 86649dd495..effd384e46 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -70,6 +70,26 @@ void listnode_add(struct list *list, void *val)
list->count++;
}
+void listnode_add_head(struct list *list, void *val)
+{
+ struct listnode *node;
+
+ assert(val != NULL);
+
+ node = listnode_new();
+
+ node->next = list->head;
+ node->data = val;
+
+ if (list->head == NULL)
+ list->head = node;
+ else
+ list->head->prev = node;
+ list->head = node;
+
+ list->count++;
+}
+
void listnode_add_sort(struct list *list, void *val)
{
struct listnode *n;