1 /* NFSv4.1 client for Windows
2 * Copyright © 2012 The Regents of the University of Michigan
4 * Olga Kornievskaia <aglo@umich.edu>
5 * Casey Bodley <cbodley@umich.edu>
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or (at
10 * your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * without any warranty; without even the implied warranty of merchantability
14 * or fitness for a particular purpose. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 /* doubly-linked list */
28 struct list_entry
*prev
;
29 struct list_entry
*next
;
33 #define list_container(entry, type, field) \
34 ((type*)((const char*)(entry) - (const char*)(&((type*)0)->field)))
36 #define list_for_each(entry, head) \
37 for (entry = (head)->next; entry != (head); entry = entry->next)
39 #define list_for_each_tmp(entry, tmp, head) \
40 for (entry = (head)->next, tmp = entry->next; entry != (head); \
41 entry = tmp, tmp = entry->next)
43 #define list_for_each_reverse(entry, head) \
44 for (entry = (head)->prev; entry != (head); entry = entry->prev)
46 #define list_for_each_reverse_tmp(entry, tmp, head) \
47 for (entry = (head)->next, tmp = entry->next; entry != (head); \
48 entry = tmp, tmp = entry->next)
51 static void list_init(
52 struct list_entry
*head
)
58 static int list_empty(
59 struct list_entry
*head
)
61 return head
->next
== head
;
65 struct list_entry
*entry
,
66 struct list_entry
*prev
,
67 struct list_entry
*next
)
69 /* assert(prev->next == next && next->prev == prev); */
76 static void list_add_head(
77 struct list_entry
*head
,
78 struct list_entry
*entry
)
80 list_add(entry
, head
, head
->next
);
83 static void list_add_tail(
84 struct list_entry
*head
,
85 struct list_entry
*entry
)
87 list_add(entry
, head
->prev
, head
);
90 static void list_remove(
91 struct list_entry
*entry
)
93 if (!list_empty(entry
)) {
94 entry
->next
->prev
= entry
->prev
;
95 entry
->prev
->next
= entry
->next
;
100 typedef int (*list_compare_fn
)(const struct list_entry
*, const void*);
102 static struct list_entry
* list_search(
103 const struct list_entry
*head
,
105 list_compare_fn compare
)
107 struct list_entry
*entry
;
108 list_for_each(entry
, head
)
109 if (compare(entry
, value
) == 0)
114 #endif /* !NFS41_LIST_H */