-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlist.c
48 lines (42 loc) · 764 Bytes
/
list.c
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
#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* head)
{
struct list_head* next = head->next;
next->prev = new;
new->next = next;
head->next = new;
new->prev = head;
}
void
list_add_tail(struct list_head* new, struct list_head* head)
{
struct list_head* prev = head->prev;
prev->next = new;
new->prev = prev;
head->prev = new;
new->next = head;
}
void
list_del(struct list_head* entry)
{
entry->next->prev = entry->prev;
entry->prev->next = entry->next;
}
void
list_del_init(struct list_head* entry)
{
list_del(entry);
INIT_LIST_HEAD(entry);
}
int
list_empty(struct list_head* head)
{
return head->next == head;
}