mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-12-27 05:49:52 +07:00
kmod_list: add helper kmod_list_insert_before()
This commit is contained in:
parent
86e8788572
commit
b91a1c6d3d
@ -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;
|
||||
|
@ -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) \
|
||||
|
Loading…
Reference in New Issue
Block a user