2 * Copyright (C) 2002 Free Software Foundation, Inc.
3 * This file is part of the GNU C Library.
4 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 /* The definitions of this file are adopted from those which can be
25 found in the Linux kernel headers to enable people familiar with
26 the latter find their way in these sources as well. */
29 /* Basic type for the double-link list. */
32 struct bt_list_head
*next
;
33 struct bt_list_head
*prev
;
37 /* Define a variable with the head and tail of the list. */
38 #define BT_LIST_HEAD(name) \
39 struct bt_list_head name = { &(name), &(name) }
41 /* Initialize a new list head. */
42 #define BT_INIT_LIST_HEAD(ptr) \
43 (ptr)->next = (ptr)->prev = (ptr)
45 #define BT_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
47 /* Add new element at the head of the list. */
49 bt_list_add (struct bt_list_head
*newp
, struct bt_list_head
*head
)
51 head
->next
->prev
= newp
;
52 newp
->next
= head
->next
;
58 /* Add new element at the tail of the list. */
60 bt_list_add_tail (struct bt_list_head
*newp
, struct bt_list_head
*head
)
62 head
->prev
->next
= newp
;
64 newp
->prev
= head
->prev
;
69 /* Remove element from list. */
71 __bt_list_del (struct bt_list_head
*prev
, struct bt_list_head
*next
)
77 /* Remove element from list. */
79 bt_list_del (struct bt_list_head
*elem
)
81 __bt_list_del (elem
->prev
, elem
->next
);
84 /* delete from list, add to another list as head */
86 bt_list_move (struct bt_list_head
*elem
, struct bt_list_head
*head
)
88 __bt_list_del (elem
->prev
, elem
->next
);
89 bt_list_add (elem
, head
);
92 /* replace an old entry.
95 bt_list_replace(struct bt_list_head
*old
, struct bt_list_head
*_new
)
97 _new
->next
= old
->next
;
98 _new
->prev
= old
->prev
;
99 _new
->prev
->next
= _new
;
100 _new
->next
->prev
= _new
;
103 /* Join two lists. */
105 bt_list_splice (struct bt_list_head
*add
, struct bt_list_head
*head
)
107 /* Do nothing if the list which gets added is empty. */
108 if (add
!= add
->next
)
110 add
->next
->prev
= head
;
111 add
->prev
->next
= head
->next
;
112 head
->next
->prev
= add
->prev
;
113 head
->next
= add
->next
;
118 /* Get typed element from list at a given position. */
119 #define bt_list_entry(ptr, type, member) \
120 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
124 /* Iterate forward over the elements of the list. */
125 #define bt_list_for_each(pos, head) \
126 for (pos = (head)->next; pos != (head); pos = pos->next)
129 /* Iterate forward over the elements of the list. */
130 #define bt_list_for_each_prev(pos, head) \
131 for (pos = (head)->prev; pos != (head); pos = pos->prev)
134 /* Iterate backwards over the elements list. The list elements can be
135 removed from the list while doing this. */
136 #define bt_list_for_each_prev_safe(pos, p, head) \
137 for (pos = (head)->prev, p = pos->prev; \
139 pos = p, p = pos->prev)
141 #define bt_list_for_each_entry(pos, head, member) \
142 for (pos = bt_list_entry((head)->next, typeof(*pos), member); \
143 &pos->member != (head); \
144 pos = bt_list_entry(pos->member.next, typeof(*pos), member))
146 #define bt_list_for_each_entry_reverse(pos, head, member) \
147 for (pos = bt_list_entry((head)->prev, typeof(*pos), member); \
148 &pos->member != (head); \
149 pos = bt_list_entry(pos->member.prev, typeof(*pos), member))
151 #define bt_list_for_each_entry_safe(pos, p, head, member) \
152 for (pos = bt_list_entry((head)->next, typeof(*pos), member), \
153 p = bt_list_entry(pos->member.next,typeof(*pos), member); \
154 &pos->member != (head); \
155 pos = p, p = bt_list_entry(pos->member.next, typeof(*pos), member))
157 static inline int bt_list_empty(struct bt_list_head
*head
)
159 return head
== head
->next
;
162 static inline void bt_list_replace_init(struct bt_list_head
*old
,
163 struct bt_list_head
*_new
)
165 struct bt_list_head
*head
= old
->next
;
167 bt_list_add_tail(_new
, head
);
168 BT_INIT_LIST_HEAD(old
);
171 #endif /* _BT_LIST_H */
This page took 0.032767 seconds and 4 git commands to generate.