-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.c
54 lines (46 loc) · 920 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
49
50
51
52
53
54
/*
* Copyright (c) 2018 Amol Surati
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <sys/list.h>
void init_list_head(struct list_head *head)
{
head->next = head->prev = head;
}
char list_empty(const struct list_head *head)
{
return head->next == head;
}
static void list_add_between(struct list_head *n,
struct list_head *prev,
struct list_head *next)
{
n->next = next;
n->prev = prev;
next->prev = n;
prev->next = n;
}
void list_add(struct list_head *n, struct list_head *head)
{
list_add_between(n, head, head->next);
}
void list_add_tail(struct list_head *n, struct list_head *head)
{
list_add_between(n, head->prev, head);
}
void list_del(struct list_head *e)
{
struct list_head *p, *n;
n = e->next;
p = e->prev;
p->next = n;
n->prev = p;
}
struct list_head *list_del_head(struct list_head *head)
{
struct list_head *e;
e = head->next;
list_del(e);
return e;
}