-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist-batman.h
102 lines (80 loc) · 3.04 KB
/
list-batman.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Copyright (C) 2006 B.A.T.M.A.N. contributors:
* Marek Lindner
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA
*
*/
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
/*
* XXX: Resolve conflict between this file and <sys/queue.h> on BSD systems.
*/
#ifdef LIST_HEAD
#undef LIST_HEAD
#endif
/*
* Simple linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
struct list_head {
struct list_head *next;
};
struct list_head_first {
struct list_head *next, *prev;
};
void list_add( struct list_head *new, struct list_head_first *head );
void list_add_tail( struct list_head *new, struct list_head_first *head );
void list_add_before( struct list_head *prev_node, struct list_head *next_node, struct list_head *new_node );
void list_del( struct list_head *prev_entry, struct list_head *entry, struct list_head_first *head );
//int list_empty( struct list_head_first *head );
#define list_empty(lst) ((lst)->next == (struct list_head *)(lst))
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); \
} while (0)
#define INIT_LIST_HEAD_FIRST(ptr) do { \
ptr.next = (struct list_head *)&ptr; ptr.prev = (struct list_head *)&ptr; \
} while (0)
#define SIMPEL_LIST(lst) struct list_head_first lst = { (struct list_head *)&lst, (struct list_head *)&lst }
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (struct list_head *)(head); \
pos = pos->next)
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the &struct list_head to use as a loop counter.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (struct list_head *)(head); \
pos = n, n = pos->next)
#endif