liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
/*
 * Simple list implementation mostly take from the Linux Kernel
 */
 
#include <stdlib.h>
#include "list.h"
 
void INIT_LIST_HEAD(struct list_head *list)
{
   list->next = list;
   list->prev = list;
}
 
void __list_add(struct list_head *new,
       struct list_head *prev, struct list_head *next)
{
   next->prev = new;
   new->next = next;
   new->prev = prev;
   prev->next = new;
}
 
void __list_del(struct list_head *prev, struct list_head *next)
{
   next->prev = prev;
   prev->next = next;
}
 
void list_add(struct list_head *new, struct list_head *head)
{
   __list_add(new, head, head->next);
}
 
void list_add_tail(struct list_head *new, struct list_head *head)
{
   __list_add(new, head->prev, head);
}
 
void list_del(struct list_head *entry)
{
   __list_del(entry->prev, entry->next);
   entry->next = NULL;
   entry->prev = NULL;
}
 
void list_replace(struct list_head *old, struct list_head *new)
{
   new->next = old->next;
   new->next->prev = new;
   new->prev = old->prev;
   new->prev->next = new;
}