]> granicus.if.org Git - sudo/commitdiff
Add tq_remove
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 27 Feb 2010 18:17:58 +0000 (13:17 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 27 Feb 2010 18:17:58 +0000 (13:17 -0500)
include/list.h
src/list.c

index b2842ec652f7996cbf8491fd65ac45f18b312727..8e0f8bd8e53a072a9de063bfa4ad1434c9736957 100644 (file)
@@ -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 */
index 60c1138026ac7ad0c84858cbd4ad959820abc385..1d8c2012ba29f603784c3aa299549fa5b16bbcf1 100644 (file)
@@ -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;
+       }
+    }
+}