about summary refs log tree commit diff
path: root/src/c-list
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-08-16 18:24:19 +0200
committerMichael Biebl <biebl@debian.org>2022-08-16 18:24:19 +0200
commit0018d1f3cf71d680d7b6bceda55a5717244d8b26 (patch)
treea058f1d106d172d3354179437ef034c9355cdf9c /src/c-list
parent6accbd3ec0e42d8633bbde4d47ed7bfe854e7e0b (diff)
New upstream version 1.39.90 upstream/1.39.90
Diffstat (limited to 'src/c-list')
-rw-r--r--src/c-list/src/c-list.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/c-list/src/c-list.h b/src/c-list/src/c-list.h
index 69de0b31..711b54d6 100644
--- a/src/c-list/src/c-list.h
+++ b/src/c-list/src/c-list.h
@@ -260,6 +260,31 @@ static inline void c_list_splice(CList *target, CList *source) {
 }
 
 /**
+ * c_list_split() - split one list in two
+ * @source:     the list to split
+ * @where:      new starting element of newlist
+ * @target:     new list
+ *
+ * This splits @source in two. All elements following @where (including @where)
+ * are moved to @target, replacing any old list. If @where points to @source
+ * (i.e., the end of the list), @target will be empty.
+ */
+static inline void c_list_split(CList *source, CList *where, CList *target) {
+        if (where == source) {
+                *target = (CList)C_LIST_INIT(*target);
+        } else {
+                target->next = where;
+                target->prev = source->prev;
+
+                where->prev->next = source;
+                source->prev = where->prev;
+
+                where->prev = target;
+                target->prev->next = target;
+        }
+}
+
+/**
  * c_list_first() - return pointer to first element, or NULL if empty
  * @list:               list to operate on, or NULL
  *