Merge branch 'collectd-4.1' into collectd-4.2
[collectd.git] / src / utils_llist.c
index 2e04152..d5db9dc 100644 (file)
@@ -21,6 +21,8 @@
  *   Florian Forster <octo at verplant.org>
  */
 
+#include "config.h"
+
 #include <stdlib.h>
 #include <string.h>
 
@@ -108,6 +110,25 @@ void llist_prepend (llist_t *l, llentry_t *e)
 {
        e->next = l->head;
        l->head = e;
+
+       if (l->tail == NULL)
+               l->tail = e;
+}
+
+void llist_remove (llist_t *l, llentry_t *e)
+{
+       llentry_t *prev;
+
+       prev = l->head;
+       while ((prev != NULL) && (prev->next != e))
+               prev = prev->next;
+
+       if (prev != NULL)
+               prev->next = e->next;
+       if (l->head == e)
+               l->head = e->next;
+       if (l->tail == e)
+               l->tail = prev;
 }
 
 llentry_t *llist_search (llist_t *l, const char *key)