mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-16 18:50:13 +00:00
lib: linklist: add listnode_add_before()
This utility function, to join the zoo that the Quagga linked-list implementation has accumulated, does an insert-before while returning the newly allocated node. It is similar to: - listnode_add_after(), but - complementary direction - returns allocated node - list_add_node_prev(), but - supports before == NULL - returns allocated node In general, the entire linked-list implementation is in bad shape, and while it needs a cleanup / rewrite / replacement, this would both cause significant conflicts and block other cleanups... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
16f5949d44
commit
b21e9619c5
@ -159,6 +159,44 @@ listnode_add_after (struct list *list, struct listnode *pp, void *val)
|
|||||||
list->count++;
|
list->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct listnode *
|
||||||
|
listnode_add_before (struct list *list, struct listnode *pp, void *val)
|
||||||
|
{
|
||||||
|
struct listnode *nn;
|
||||||
|
|
||||||
|
assert (val != NULL);
|
||||||
|
|
||||||
|
nn = listnode_new ();
|
||||||
|
nn->data = val;
|
||||||
|
|
||||||
|
if (pp == NULL)
|
||||||
|
{
|
||||||
|
if (list->tail)
|
||||||
|
list->tail->next = nn;
|
||||||
|
else
|
||||||
|
list->head = nn;
|
||||||
|
|
||||||
|
nn->prev = list->tail;
|
||||||
|
nn->next = pp;
|
||||||
|
|
||||||
|
list->tail = nn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pp->prev)
|
||||||
|
pp->prev->next = nn;
|
||||||
|
else
|
||||||
|
list->head = nn;
|
||||||
|
|
||||||
|
nn->prev = pp->prev;
|
||||||
|
nn->next = pp;
|
||||||
|
|
||||||
|
pp->prev = nn;
|
||||||
|
}
|
||||||
|
list->count++;
|
||||||
|
return nn;
|
||||||
|
}
|
||||||
|
|
||||||
/* Move given listnode to tail of the list */
|
/* Move given listnode to tail of the list */
|
||||||
void
|
void
|
||||||
listnode_move_to_tail (struct list *l, struct listnode *n)
|
listnode_move_to_tail (struct list *l, struct listnode *n)
|
||||||
|
@ -68,6 +68,7 @@ extern void list_free (struct list *);
|
|||||||
extern void listnode_add (struct list *, void *);
|
extern void listnode_add (struct list *, void *);
|
||||||
extern void listnode_add_sort (struct list *, void *);
|
extern void listnode_add_sort (struct list *, void *);
|
||||||
extern void listnode_add_after (struct list *, struct listnode *, void *);
|
extern void listnode_add_after (struct list *, struct listnode *, void *);
|
||||||
|
extern struct listnode *listnode_add_before (struct list *, struct listnode *, void *);
|
||||||
extern void listnode_move_to_tail (struct list *, struct listnode *);
|
extern void listnode_move_to_tail (struct list *, struct listnode *);
|
||||||
extern void listnode_delete (struct list *, void *);
|
extern void listnode_delete (struct list *, void *);
|
||||||
extern struct listnode *listnode_lookup (struct list *, void *);
|
extern struct listnode *listnode_lookup (struct list *, void *);
|
||||||
|
Loading…
Reference in New Issue
Block a user