// SPDX-License-Identifier: MIT #include "list.h" /* Unlink a node from a list. */ void list_del(list_t* node) { node->prev->next = node->next; node->next->prev = node->prev; node->next = node->prev = node; } /* Add an element after another in a list. */ void list_add(list_t* node, list_t* to_add) { to_add->next = node->next; to_add->prev = node; node->next->prev = to_add; node->next = to_add; } void list_add_tail(list_t* node, list_t* to_add) { to_add->next = node; to_add->prev = node->prev; node->prev->next = to_add; node->prev = to_add; } list_t* list_pop(list_t* head) { list_t* node; if (list_empty(head)) return NULL; node = head->next; list_del(node); return node; } list_t* list_pop_tail(list_t* head) { list_t* node; if (list_empty(head)) return NULL; node = head->prev; list_del(node); return node; } /* Move the root of a list to a different location. */ void list_move(list_t* dst, list_t* src) { dst->next = dst->prev = dst; if (list_empty(src)) return; *dst = *src; src->next = src->prev = src; dst->next->prev = dst; dst->prev->next = dst; }