Tomato 1.24
[tomato.git] / release / src / router / busybox / e2fsprogs / old_e2fsprogs / ext2fs / kernel-list.h
blobd80716a4540840a3f9495f6be7a68356e14fe31c
1 /* vi: set sw=4 ts=4: */
2 #ifndef LINUX_LIST_H
3 #define LINUX_LIST_H 1
5 /*
6 * Simple doubly linked list implementation.
8 * Some of the internal functions ("__xxx") are useful when
9 * manipulating whole lists rather than single entries, as
10 * sometimes we already know the next/prev entries and we can
11 * generate better code by using them directly rather than
12 * using the generic single-entry routines.
15 struct list_head {
16 struct list_head *next, *prev;
19 #define LIST_HEAD_INIT(name) { &(name), &(name) }
21 #define LIST_HEAD(name) \
22 struct list_head name = { &name, &name }
24 #define INIT_LIST_HEAD(ptr) do { \
25 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
26 } while (0)
28 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
29 #define __inline__
30 #endif
33 * Insert a new entry between two known consecutive entries.
35 * This is only for internal list manipulation where we know
36 * the prev/next entries already!
38 static __inline__ void __list_add(struct list_head * new,
39 struct list_head * prev,
40 struct list_head * next)
42 next->prev = new;
43 new->next = next;
44 new->prev = prev;
45 prev->next = new;
49 * Insert a new entry after the specified head..
51 static __inline__ void list_add(struct list_head *new, struct list_head *head)
53 __list_add(new, head, head->next);
57 * Insert a new entry at the tail
59 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
61 __list_add(new, head->prev, head);
65 * Delete a list entry by making the prev/next entries
66 * point to each other.
68 * This is only for internal list manipulation where we know
69 * the prev/next entries already!
71 static __inline__ void __list_del(struct list_head * prev,
72 struct list_head * next)
74 next->prev = prev;
75 prev->next = next;
78 static __inline__ void list_del(struct list_head *entry)
80 __list_del(entry->prev, entry->next);
83 static __inline__ int list_empty(struct list_head *head)
85 return head->next == head;
89 * Splice in "list" into "head"
91 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
93 struct list_head *first = list->next;
95 if (first != list) {
96 struct list_head *last = list->prev;
97 struct list_head *at = head->next;
99 first->prev = head;
100 head->next = first;
102 last->next = at;
103 at->prev = last;
107 #define list_entry(ptr, type, member) \
108 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
110 #define list_for_each(pos, head) \
111 for (pos = (head)->next; pos != (head); pos = pos->next)
113 #endif