]> git.ipfire.org Git - thirdparty/bird.git/blame - lib/lists.h
Added macros for walking lists backwards.
[thirdparty/bird.git] / lib / lists.h
CommitLineData
58ef912c
MM
1/*
2 * BIRD Library -- Linked Lists
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_LISTS_H_
10#define _BIRD_LISTS_H_
11
12typedef struct node {
13 struct node *next, *prev;
14} node;
15
16typedef struct list { /* In fact two overlayed nodes */
17 struct node *head, *null, *tail;
18} list;
19
20#define NODE (node *)
21#define HEAD(list) ((void *)((list).head))
22#define TAIL(list) ((void *)((list).tail))
d92882be 23#define WALK_LIST(n,list) for(n=HEAD(list);(NODE (n))->next; \
58ef912c 24 n=(void *)((NODE (n))->next))
d92882be
MM
25#define WALK_LIST_DELSAFE(n,nxt,list) \
26 for(n=HEAD(list); nxt=(void *)((NODE (n))->next); n=(void *) nxt)
b6628a8c
MM
27#define WALK_LIST_BACKWARDS(n,list) for(n=TAIL(list);(NODE (n))->prev; \
28 n=(void *)((NODE (n))->prev))
29#define WALK_LIST_BACKWARDS_DELSAFE(n,prv,list) \
30 for(n=TAIL(list); prv=(void *)((NODE (n))->prev); n=(void *) prv)
aea2dcab 31
58ef912c
MM
32#define EMPTY_LIST(list) (!(list).head->next)
33
34void add_tail(list *, node *);
35void add_head(list *, node *);
36void rem_node(node *);
37void add_tail_list(list *, list *);
38void init_list(list *);
39void insert_node(node *, node *);
40
41#ifndef _BIRD_LISTS_C_
42#define LIST_INLINE extern inline
18c8241a 43#include "lib/lists.c"
58ef912c
MM
44#undef LIST_INLINE
45#else
46#define LIST_INLINE
47#endif
48
49#endif