summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'list.c')
-rw-r--r--list.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/list.c b/list.c
index e9dcebb..4e80300 100644
--- a/list.c
+++ b/list.c
@@ -52,12 +52,40 @@ void *list_shift(struct list *list) {
node = list->first;
list->first = node->next;
+ if (!list->first)
+ list->last = NULL;
data = node->data;
free(node);
return data;
}
+/* removes first entry with matching data pointer */
+void list_removedata(struct list *list, void *data) {
+ struct list_node *node, *t;
+
+ if (!list->first)
+ return;
+
+ node = list->first;
+ if (node->data == data) {
+ list->first = node->next;
+ if (!list->first)
+ list->last = NULL;
+ free(node);
+ return;
+ }
+ for (; node->next; node = node->next)
+ if (node->next->data == data) {
+ t = node->next;
+ node->next = node->next->next;
+ if (!node->next) /* we removed the last one */
+ list->last = node;
+ free(t);
+ return;
+ }
+}
+
/* returns first node */
struct list_node *list_first(struct list *list) {
return list->first;