1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 /* The definitions of this file are adopted from those which can be
23 found in the Linux kernel headers to enable people familiar with
24 the latter find their way in these sources as well. */
27 /* Basic type for the double-link list. */
28 typedef struct list_head
30 struct list_head *next;
31 struct list_head *prev;
35 /* Define a variable with the head and tail of the list. */
36 #define LIST_HEAD(name) \
37 list_t name = { &(name), &(name) }
39 /* Initialize a new list head. */
40 #define INIT_LIST_HEAD(ptr) \
41 (ptr)->next = (ptr)->prev = (ptr)
44 /* Add new element at the head of the list. */
45 static __inline__ void
46 list_add (list_t *newp, list_t *head)
48 head->next->prev = newp;
49 newp->next = head->next;
55 /* Add new element at the tail of the list. */
56 static __inline__ void
57 list_add_tail (list_t *newp, list_t *head)
59 head->prev->next = newp;
61 newp->prev = head->prev;
66 /* Remove element from list. */
67 static __inline__ void
68 list_del (list_t *elem)
70 elem->next->prev = elem->prev;
71 elem->prev->next = elem->next;
76 static __inline__ void
77 list_splice (list_t *add, list_t *head)
79 /* Do nothing if the list which gets added is empty. */
82 add->next->prev = head;
83 add->prev->next = head->next;
84 head->next->prev = add->prev;
85 head->next = add->next;
90 /* Get typed element from list at a given position. */
91 #define list_entry(ptr, type, member) \
92 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
96 /* Iterate forward over the elements of the list. */
97 #define list_for_each(pos, head) \
98 for (pos = (head)->next; pos != (head); pos = pos->next)
101 /* Iterate forward over the elements of the list. */
102 #define list_for_each_prev(pos, head) \
103 for (pos = (head)->prev; pos != (head); pos = pos->prev)
106 /* Iterate backwards over the elements list. The list elements can be
107 removed from the list while doing this. */
108 #define list_for_each_prev_safe(pos, p, head) \
109 for (pos = (head)->prev, p = pos->prev; \
111 pos = p, p = pos->prev)