]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
introduce kmod_list_last()
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 17 Dec 2011 00:32:33 +0000 (22:32 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 17 Dec 2011 21:43:11 +0000 (19:43 -0200)
This gets the last element in the list, that is, the previous element
of the head.

libkmod/libkmod-list.c
libkmod/libkmod.h
libkmod/libkmod.sym

index 5ec33a2a2d10eeb02556fcb1d0b22aa2185f6002..4b68b77e28372552bb4f8f0e07722fb39533a937 100644 (file)
@@ -310,3 +310,23 @@ KMOD_EXPORT struct kmod_list *kmod_list_next(const struct kmod_list *list,
 
        return container_of(curr->node.next, struct kmod_list, node);
 }
+
+/**
+ * kmod_list_last:
+ * @list: the head of the list
+ *
+ * Get the last element of the @list. As @list is a circular list,
+ * this is a cheap operation O(1) with the last element being the
+ * previous element.
+ *
+ * If the list has a single element it will return the list itself (as
+ * expected, and this is what differentiates from kmod_list_prev()).
+ *
+ * Returns: last node at @list or NULL if the list is empty.
+ */
+KMOD_EXPORT struct kmod_list *kmod_list_last(const struct kmod_list *list)
+{
+       if (list == NULL)
+               return NULL;
+       return container_of(list->node.prev, struct kmod_list, node);
+}
index 194946d186f340bda6c629fcfbb4dd5c1b246223..37abbcc66ad5d293dbb3e652abc0f8ab3948145b 100644 (file)
@@ -62,6 +62,8 @@ struct kmod_list *kmod_list_next(const struct kmod_list *first_entry,
                                                const struct kmod_list *list_entry);
 struct kmod_list *kmod_list_prev(const struct kmod_list *first_entry,
                                                const struct kmod_list *list_entry);
+struct kmod_list *kmod_list_last(const struct kmod_list *first_entry);
+
 #define kmod_list_foreach(list_entry, first_entry) \
        for (list_entry = first_entry; \
                list_entry != NULL; \
index 71b7ccc856d877d5a41cf4022217de5f57141128..664fd6bb4b73d2c2e55a35139bc9927fbb403e23 100644 (file)
@@ -11,6 +11,7 @@ global:
        kmod_unref;
        kmod_list_next;
        kmod_list_prev;
+        kmod_list_last;
 
        kmod_load_resources;
        kmod_unload_resources;