diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-01-24 08:51:50 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-01-24 08:51:50 +0000 |
commit | 170d63190a3cfb0c12ee9ddfe07b21f20825bd6f (patch) | |
tree | c1cad21e75daf695f61f83ca1072d0a52343a673 /lib/libalpm/alpm_list.c | |
parent | 1b61cc8c69025ddd394401a506b21f16df5d4e6d (diff) | |
download | pacman-170d63190a3cfb0c12ee9ddfe07b21f20825bd6f.tar.xz |
* Shuffled some of the alpm_list free funtions - still not perfect, but better
* Added alpm_list_remove_node for single list node removal
* Proper error checking/output for failed db_read/db_write (missing files)
* Invalid packages (missing files) are now removed from the package cache
* -Qs and -Ss output now look the same
* config.rpath causes errors on one machine I had, so I added it to CVS
* Fixed a "clobbered memory" issue when installing groups - only the outer list
should be free'd, not the contained data
Diffstat (limited to 'lib/libalpm/alpm_list.c')
-rw-r--r-- | lib/libalpm/alpm_list.c | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 26fcb3dc..edb2e8e5 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -49,33 +49,37 @@ alpm_list_t *alpm_list_new() return(list); } -/** Free a list structure and possibly the internal data as well +/** Free a list, but not the contained data * @param list the list to free - * @param fn a free function for the internal data, or NULL for none */ -void alpm_list_free(alpm_list_t *list, alpm_list_fn_free fn) +void alpm_list_free(alpm_list_t *list) { alpm_list_t *it = list; while(it) { - alpm_list_t *ptr = it->next; - if(fn && it->data) { - fn(it->data); - } - FREE(it); - it = ptr; + alpm_list_t *tmp = it->next; + free(it); + it = tmp; } } -/** Free the outer list, but not the contained data - * A minor simplification of alpm_list_free +/** Free the internal data of a list structure * @param list the list to free + * @param fn a free function for the internal data */ -void alpm_list_free_outer(alpm_list_t *list) +void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn) { - alpm_list_free(list, NULL); + alpm_list_t *it = list; + + while(it) { + if(fn && it->data) { + fn(it->data); + } + it = it->next; + } } + /* Mutators */ /** Add a new item to the list @@ -271,6 +275,31 @@ alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_ return(haystack); } +/** Remove the passed in node from the list that it is a part of + * @note this DOES NOT free the node + * @param node the list node we're removing + * @return the node which took the place of this one + */ +alpm_list_t *alpm_list_remove_node(alpm_list_t *node) +{ + if(!node) return(NULL); + + alpm_list_t *ret = NULL; + + if(node->prev) { + node->prev->next = node->next; + ret = node->prev; + node->prev = NULL; + } + if(node->next) { + node->next->prev = node->prev; + ret = node->next; + node->next = NULL; + } + + return(ret); +} + /** Create a new list without any duplicates * @note DOES NOT copy data members * @param list the list to copy |