commit: a5914c0a9ee9bbd02d56da2d02ef5d662a88454a
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Feb 6 14:51:21 2026 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Feb 6 14:51:21 2026 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a5914c0a
libq/array: add array_move function
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/array.c | 23 +++++++++++++++++++++++
libq/array.h | 1 +
2 files changed, 24 insertions(+)
diff --git a/libq/array.c b/libq/array.c
index e7be9e43..9d4e0175 100644
--- a/libq/array.c
+++ b/libq/array.c
@@ -119,6 +119,29 @@ void *array_append_copy
return ret;
}
+/* moves all elements from src into dst, leaving src an empty array */
+void array_move
+(
+ array *dst,
+ array *src
+)
+{
+ void *elem;
+ size_t n;
+
+ if (dst == NULL ||
+ src == NULL ||
+ array_cnt(src) == 0)
+ return;
+
+ array_for_each(src, n, elem)
+ array_append(dst, elem);
+
+ /* we lack an array_clear or something, sofar we didn't really have a
+ * need for it, so simply declare the src empty */
+ src->len = 0;
+}
+
/* removes the given element from the array and returns the pointer to
* the data removed from the array
* the caller should ensure the pointer is freed if necessary */
diff --git a/libq/array.h b/libq/array.h
index 6938ec7b..71d0cafa 100644
--- a/libq/array.h
+++ b/libq/array.h
@@ -21,6 +21,7 @@ void array_free(array *arr);
void array_deepfree(array *arr, array_free_cb *func);
void *array_append(array *arr, void *data);
void *array_append_copy(array *arr, const void *data, size_t len);
+void array_move(array *dst, array *src);
void *array_remove(array *arr, size_t elem);
void array_delete(array *arr, size_t elem, array_free_cb *func);
size_t array_cnt(array *arr);