introduce kmod_list_foreach_reverse().
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 17 Dec 2011 00:33:08 +0000 (22:33 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 17 Dec 2011 22:03:43 +0000 (20:03 -0200)
walks the list in the reverse order.

libkmod/libkmod-private.h
libkmod/libkmod.h

index 85cfc12..6c8fed2 100644 (file)
@@ -67,6 +67,13 @@ struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_lis
                list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \
                container_of(list_entry->node.next, struct kmod_list, node))
 
+#undef kmod_list_foreach_reverse
+#define kmod_list_foreach_reverse(list_entry, first_entry) \
+       for (list_entry = (((first_entry) == NULL) ? NULL : container_of(first_entry->node.prev, struct kmod_list, node)); \
+               list_entry != NULL; \
+               list_entry = ((list_entry == first_entry) ? NULL :      \
+               container_of(list_entry->node.prev, struct kmod_list, node)))
+
 /* libkmod.c */
 const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
 
index 37abbcc..76eaf8e 100644 (file)
@@ -69,6 +69,11 @@ struct kmod_list *kmod_list_last(const struct kmod_list *first_entry);
                list_entry != NULL; \
                list_entry = kmod_list_next(first_entry, list_entry))
 
+#define kmod_list_foreach_reverse(list_entry, first_entry) \
+       for (list_entry = kmod_list_last(first_entry); \
+               list_entry != NULL; \
+               list_entry = kmod_list_prev(first_entry, list_entry))
+
 /* Removal flags, not implemented yet */
 enum kmod_remove {
        KMOD_REMOVE_FORCE = O_TRUNC,