return node;
}
+void list_insert_after(list_t *prev, void *data)
+{
+ // prev must be valid,
+ // as we cannot return the original list head
+ list_t *node = new0(list_t);
+ node->data = data;
+ node->prev = prev;
+ node->next = prev->next;
+ prev->next = node;
+ if (node->next) node->next->prev = node;
+}
+
list_t *list_append(list_t *head, void *data)
{
list_t *last = head;
- while (last->next)
+ while (last && last->next)
last = last->next;
list_t *node = new0(list_t);
node->data = data;
return len;
}
+list_t *list_last(list_t *list)
+{
+ while (list && list->next)
+ list = list->next;
+ return list;
+}
+
+list_t *list_find(list_t *list, void *data)
+{
+ for (list_t *cur = list; cur; cur = cur->next)
+ if (cur->data == data)
+ return cur;
+ return NULL;
+}
+
/* Misc */
int error(char *fmt, ...)
{