]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: introduce new list_dup() API 6889/head
authorRenato Westphal <renato@opensourcerouting.org>
Tue, 11 Aug 2020 02:21:59 +0000 (23:21 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 11 Aug 2020 23:41:44 +0000 (20:41 -0300)
This new function will be used by the upcoming TI-LFA code.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/linklist.c
lib/linklist.h

index 2936c5b502a0fa38f4474c473c810da1b431ac89..84dc6e1419705f3d3a5666c27fc9520f2b56852b 100644 (file)
@@ -150,6 +150,23 @@ bool listnode_add_sort_nodup(struct list *list, void *val)
        return true;
 }
 
+struct list *list_dup(struct list *list)
+{
+       struct list *dup;
+       struct listnode *node;
+       void *data;
+
+       assert(list);
+
+       dup = list_new();
+       dup->cmp = list->cmp;
+       dup->del = list->del;
+       for (ALL_LIST_ELEMENTS_RO(list, node, data))
+               listnode_add(dup, data);
+
+       return dup;
+}
+
 void listnode_add_sort(struct list *list, void *val)
 {
        struct listnode *n;
index 94a1a1604a3899c36a7f6e6f3d112db1c4c7e651..d8820c924d9170977e8d313b070fec2603b8dd67 100644 (file)
@@ -327,6 +327,19 @@ extern void list_filter_out_nodes(struct list *list, bool (*cond)(void *data));
  */
 
 extern bool listnode_add_sort_nodup(struct list *list, void *val);
+
+/*
+ * Duplicate the specified list, creating a shallow copy of each of its
+ * elements.
+ *
+ * list
+ *    list to duplicate
+ *
+ * Returns:
+ *    the duplicated list
+ */
+extern struct list *list_dup(struct list *list);
+
 /* List iteration macro.
  * Usage: for (ALL_LIST_ELEMENTS (...) { ... }
  * It is safe to delete the listnode using this macro.