FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-03-2011, 12:26 AM
Allan McRae
 
Default Add alpm_list_previous method

Helper function to get the previous item in a list

Signed-off-by: Allan McRae <allan@archlinux.org>
---
lib/libalpm/alpm_list.c | 18 ++++++++++++++++++
lib/libalpm/alpm_list.h | 1 +
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index c2b30ad..1976e13 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -556,6 +556,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.
*
* @param list the list
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index 1f6393a..27a76d1 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -70,6 +70,7 @@ alpm_list_t *alpm_list_reverse(alpm_list_t *list);
alpm_list_t *alpm_list_first(const alpm_list_t *list);
alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
alpm_list_t *alpm_list_next(const alpm_list_t *list);
+alpm_list_t *alpm_list_previous(const alpm_list_t *list, const alpm_list_t *node);
alpm_list_t *alpm_list_last(const alpm_list_t *list);
void *alpm_list_getdata(const alpm_list_t *entry);

--
1.7.6
 

Thread Tools




All times are GMT. The time now is 03:54 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org