introduce kmod_list_foreach_reverse().

walks the list in the reverse order.
This commit is contained in:
Gustavo Sverzut Barbieri 2011-12-16 22:33:08 -02:00 committed by Lucas De Marchi
parent fecbad2f22
commit d6b55b7d18
2 changed files with 12 additions and 0 deletions

View 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 : \ list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \
container_of(list_entry->node.next, struct kmod_list, node)) 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 */ /* libkmod.c */
const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));

View File

@ -69,6 +69,11 @@ struct kmod_list *kmod_list_last(const struct kmod_list *first_entry);
list_entry != NULL; \ list_entry != NULL; \
list_entry = kmod_list_next(first_entry, list_entry)) 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 */ /* Removal flags, not implemented yet */
enum kmod_remove { enum kmod_remove {
KMOD_REMOVE_FORCE = O_TRUNC, KMOD_REMOVE_FORCE = O_TRUNC,