summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm_list.c26
-rw-r--r--lib/libalpm/alpm_list.h1
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 2301411a..64877530 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -361,8 +361,6 @@ alpm_list_t SYMEXPORT *alpm_list_remove_dupes(const alpm_list_t *list)
/**
* @brief Copy a string list, including data.
*
- * This is gross, assumes string data members.
- *
* @param list the list to copy
*
* @return a copy of the original list
@@ -397,6 +395,30 @@ alpm_list_t SYMEXPORT *alpm_list_copy(const alpm_list_t *list)
}
/**
+ * @brief Copy a list and copy the data.
+ *
+ * The data must be constant size!
+ *
+ * @param list the list to copy
+ *
+ * @return a copy of the original list, data copied as well
+ */
+alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list)
+{
+ const alpm_list_t *lp = list;
+ alpm_list_t *newlist = NULL;
+ while(lp) {
+ void *newdata = calloc(1, sizeof(lp->data));
+ if(newdata) {
+ memcpy(newdata, lp->data, sizeof(lp->data));
+ newlist = alpm_list_add(newlist, newdata);
+ lp = lp->next;
+ }
+ }
+ return(newlist);
+}
+
+/**
* @brief Create a new list in reverse order.
*
* @param list the list to copy
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index 8fce2804..addf9505 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -61,6 +61,7 @@ alpm_list_t *alpm_list_remove_node(alpm_list_t *node);
alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list);
alpm_list_t *alpm_list_strdup(const alpm_list_t *list);
alpm_list_t *alpm_list_copy(const alpm_list_t *list);
+alpm_list_t *alpm_list_copy_data(const alpm_list_t *list);
alpm_list_t *alpm_list_reverse(alpm_list_t *list);
/* item accessors */