Use regex.[ch] from msysGit's /git
[cvsps/4msysgit.git] / cbtcommon / list.h
blob4ee245de9be329a45f888dd77c1ea8a11a0492b9
1 /*
2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
4 */
6 #ifndef _COMMON_LIST_H
7 #define _COMMON_LIST_H
9 /*
10 * Stolen from linux-2.1.131
11 * All comments from the original source unless otherwise noted
12 * Added: the CLEAR_LIST_NODE macro
16 * Simple doubly linked list implementation.
18 * Some of the internal functions ("__xxx") are useful when
19 * manipulating whole lists rather than single entries, as
20 * sometimes we already know the next/prev entries and we can
21 * generate better code by using them directly rather than
22 * using the generic single-entry routines.
25 #include "inline.h"
27 struct list_head {
28 struct list_head *next, *prev;
31 #define LIST_HEAD(name) \
32 struct list_head name = { &name, &name }
34 #define INIT_LIST_HEAD(ptr) do { \
35 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
36 } while (0)
38 #define CLEAR_LIST_NODE(ptr) do { \
39 (ptr)->next = NULL; (ptr)->prev = NULL; \
40 } while (0)
43 * Insert a new entry between two known consecutive entries.
45 * This is only for internal list manipulation where we know
46 * the prev/next entries already!
48 static INLINE void __list_add(struct list_head *li,
49 struct list_head * prev,
50 struct list_head * next)
52 next->prev = li;
53 li->next = next;
54 li->prev = prev;
55 prev->next = li;
59 * Insert a new entry after the specified head..
61 static INLINE void list_add(struct list_head *li, struct list_head *head)
63 __list_add(li, head, head->next);
67 * Delete a list entry by making the prev/next entries
68 * point to each other.
70 * This is only for internal list manipulation where we know
71 * the prev/next entries already!
73 static INLINE void __list_del(struct list_head * prev,
74 struct list_head * next)
76 next->prev = prev;
77 prev->next = next;
80 static INLINE void list_del(struct list_head *entry)
82 __list_del(entry->prev, entry->next);
85 static INLINE int list_empty(struct list_head *head)
87 return head->next == head;
91 * Splice in "list" into "head"
93 static INLINE void list_splice(struct list_head *list, struct list_head *head)
95 struct list_head *first = list->next;
97 if (first != list) {
98 struct list_head *last = list->prev;
99 struct list_head *at = head->next;
101 first->prev = head;
102 head->next = first;
104 last->next = at;
105 at->prev = last;
109 #define list_entry(ptr, type, member) \
110 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
112 #endif /* _COMMON_LIST_H */