Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/alpm_list.c
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2017-02-18 17:09:49 -0500
committerAllan McRae <allan@archlinux.org>2017-04-04 12:03:22 +1000
commita138db3c07553cfd252495a3c406e11457075e79 (patch)
treedd2e54b8339e28a3f20e2142f93be5f545ade2fc /lib/libalpm/alpm_list.c
parenta202959a1973564474d39e2dbd76ca4ad1302eed (diff)
add alpm_list_append_strdup
Makes error detection and handling easier for a common operation. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/alpm_list.c')
-rw-r--r--lib/libalpm/alpm_list.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 36b01c71..0f1b819c 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -132,6 +132,26 @@ alpm_list_t SYMEXPORT *alpm_list_append(alpm_list_t **list, void *data)
}
/**
+ * @brief Duplicate and append a string to a list.
+ *
+ * @param list the list to append to
+ * @param data the string to duplicate and append
+ *
+ * @return the newly added item
+ */
+alpm_list_t SYMEXPORT *alpm_list_append_strdup(alpm_list_t **list, const char *data)
+{
+ alpm_list_t *ret;
+ char *dup;
+ if((dup = strdup(data)) && (ret = alpm_list_append(list, dup))) {
+ return ret;
+ } else {
+ free(dup);
+ return NULL;
+ }
+}
+
+/**
* @brief Add items to a list in sorted order.
*
* @param list the list to add to