From ab79b13079ea6c0c7b66e4c5d14686f06ba759ae Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sun, 3 Jul 2011 10:10:36 +1000 Subject: Add alpm_list_previous method Helper function to get the previous item in a list Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- lib/libalpm/alpm_list.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/libalpm/alpm_list.c') diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index c2b30adc..1976e13d 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -555,6 +555,24 @@ inline alpm_list_t SYMEXPORT *alpm_list_next(const alpm_list_t *node) } } +/** + * @brief Get the previous element of a list. + * + * @param list the list head + * @param node the list node + * + * @return the previous element, or NULL when no previous element exist + */ +inline alpm_list_t SYMEXPORT *alpm_list_previous(const alpm_list_t *list, + const alpm_list_t *node) +{ + if(node && node != list) { + return node->prev; + } else { + return NULL; + } +} + /** * @brief Get the last item in the list. * -- cgit v1.2.3-24-g4f1b