summaryrefslogtreecommitdiffstats
path: root/src/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/list.h b/src/list.h
index b0e174d..a18068a 100644
--- a/src/list.h
+++ b/src/list.h
@@ -7,29 +7,40 @@
const typeof( ((type *)0)->link ) *__mptr = (ptr); \
(type *)( (char *)__mptr - LINK_OFFSET(type) ); })
-#define LIST_HEAD ((struct link) { .prev = NULL, .next = NULL })
#define LINK_EMPTY ((struct link) { 0 })
#define LINK(p) (&(p)->link)
+#define LIST_INNER(list, link) \
+ (((link) != &(list)->head) && ((link) != &(list)->tail))
+
+#define LIST_ITER(list, iter) (iter) = (list)->head.next; \
+ (iter) != &(list)->tail; (iter) = (iter)->next
+
+typedef void (*link_free_func)(void *p);
+
struct link {
struct link *prev;
struct link *next;
};
-/* list_XXX functions operate on the list head */
+struct list {
+ struct link head;
+ struct link tail;
+};
-void list_free(struct link *head, void (*free_item)(void *), int offset);
-int list_empty(struct link *head);
-int list_len(struct link *head);
-int list_ffind(struct link *head, struct link *link);
-struct link *list_at(struct link *head, int n);
-void list_push_front(struct link *head, struct link *link);
-void list_push_back(struct link *head, struct link *link);
-struct link *list_pop_front(struct link *head);
+void list_init(struct list *list);
+void list_free(struct list *list, void (*free_item)(void *), int offset);
+int list_empty(struct list *list);
+int list_len(struct list *list);
+struct link *list_at(struct list *list, int n);
+void list_push_front(struct list *list, struct link *link);
+void list_push_back(struct list *list, struct link *link);
+struct link *list_pop_front(struct list *list);
+struct link *list_pop_back(struct list *list);
void link_prepend(struct link *list, struct link *link);
void link_append(struct link *list, struct link *link);
-struct link *link_back(struct link *list);
-struct link *link_pop(struct link *link);
struct link *link_iter(struct link *link, int n);
+struct link *link_pop(struct link *link);
+