common/list.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "list.h"
void list_append(struct list *list, struct list_node *node) {
struct list_node *new_stl;
if (list == NULL || node == NULL) { return; }
new_stl = list->last;
list->last = node;
node->next = NULL;
node->prev = new_stl;
if (new_stl == NULL) {
list->first = node;
} else {
new_stl->next = node;
}
}
void list_prepend(struct list *list, struct list_node *node) {
struct list_node *new_second;
if (list == NULL || node == NULL) { return; }
new_second = list->first;
list->first = node;
node->prev = NULL;
node->next = new_second;
if (new_second == NULL) {
list->last = node;
} else {
new_second->prev = node;
}
}