index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2016-01-11 09:29:22 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2016-01-15 14:47:36 +1000 |
commit | ab50864a758a7c3d26d5423521743c5753a6cffe (patch) | |
tree | ceb784be7247152d58f77428ecae8fb901413803 /lib/libalpm/alpm_list.c | |
parent | 9813107c3368684784706cf2b77bd056bea58e3c (diff) |
-rw-r--r-- | lib/libalpm/alpm_list.c | 34 |
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 62b28438..f3effc72 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -93,28 +93,42 @@ void SYMEXPORT alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn) */ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data) { - alpm_list_t *ptr, *lp; + alpm_list_append(&list, data); + return list; +} + +/** + * @brief Add a new item to the end of the list. + * + * @param list the list to add to + * @param data the new item to be added to the list + * + * @return the newly added item + */ +alpm_list_t SYMEXPORT *alpm_list_append(alpm_list_t **list, void *data) +{ + alpm_list_t *ptr; ptr = malloc(sizeof(alpm_list_t)); if(ptr == NULL) { - return list; + return NULL; } ptr->data = data; ptr->next = NULL; /* Special case: the input list is empty */ - if(list == NULL) { + if(*list == NULL) { + *list = ptr; ptr->prev = ptr; - return ptr; + } else { + alpm_list_t *lp = alpm_list_last(*list); + lp->next = ptr; + ptr->prev = lp; + (*list)->prev = ptr; } - lp = alpm_list_last(list); - lp->next = ptr; - ptr->prev = lp; - list->prev = ptr; - - return list; + return ptr; } /** |