From: Todd C. Miller Date: Sat, 27 Feb 2010 18:17:58 +0000 (-0500) Subject: Add tq_remove X-Git-Tag: SUDO_1_8_0~857 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25d3b4e51c748ea579b646b26cceba387b287477;p=sudo Add tq_remove --- diff --git a/include/list.h b/include/list.h index b2842ec65..8e0f8bd8e 100644 --- a/include/list.h +++ b/include/list.h @@ -67,9 +67,10 @@ struct n##_list { \ /* * Prototypes for list.c */ -void *tq_pop (void *); -void tq_append (void *, void *); -void list_append (void *, void *); -void list2tq (void *, void *); +void *tq_pop(void *); +void tq_append(void *, void *); +void list_append(void *, void *); +void list_remove(void *, void *); +void list2tq(void *, void *); #endif /* _SUDO_LIST_H */ diff --git a/src/list.c b/src/list.c index 60c113802..1d8c2012b 100644 --- a/src/list.c +++ b/src/list.c @@ -131,3 +131,33 @@ tq_append(vh, vl) l->prev = h->last; h->last = tail; } + +/* + * Remove element from the tail_queue + */ +void +tq_remove(vh, vl) + void *vh; + void *vl; +{ + struct list_head_proto *h = (struct list_head_proto *)vh; + struct list_proto *l = (struct list_proto *)vl; + + if (h->first == l && h->last == l) { + /* Single element in the list. */ + h->first = NULL; + h->last = NULL; + } else { + /* At least two elements in the list. */ + if (h->first == l) { + h->first = l->next; + h->first->prev = h->first; + } else if (h->last == l) { + h->last = l->prev; + h->last->next = NULL; + } else { + l->prev->next = l->next; + l->next->prev = l->prev; + } + } +}