kmod_list: add helper kmod_list_insert_before()

This commit is contained in:
Lucas De Marchi 2011-12-05 23:53:56 -02:00
parent 86e8788572
commit b91a1c6d3d
2 changed files with 32 additions and 0 deletions

View File

@ -85,6 +85,20 @@ static inline void list_node_insert_after(struct list_node *list,
list->next = node;
}
static inline void list_node_insert_before(struct list_node *list,
struct list_node *node)
{
if (list == NULL) {
list_node_init(node);
return;
}
node->next = list;
node->prev = list->prev;
list->prev->next = node;
list->prev = node;
}
struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data)
{
struct kmod_list *new;
@ -116,6 +130,23 @@ struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *dat
return list;
}
struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data)
{
struct kmod_list *new;
if (list == NULL)
return kmod_list_append(list, data);
new = malloc(sizeof(*new));
if (new == NULL)
return NULL;
new->data = (void *)data;
list_node_insert_before(&list->node, &new->node);
return new;
}
struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data)
{
struct kmod_list *new;

View File

@ -54,6 +54,7 @@ struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
unsigned int n) __must_check;
struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
#undef kmod_list_foreach
#define kmod_list_foreach(list_entry, first_entry) \