4a3879fb4039b1ff84b2fe5a52cbc5f12fd3460e
[adns] / src / dlist.h
1 /*
2 * dlist.h
3 * - macros for handling doubly linked lists
4 */
5 /*
6 * This file is part of adns, which is
7 * Copyright (C) 1997-2000,2003,2006,2014 Ian Jackson
8 * Copyright (C) 1999-2000,2003,2006 Tony Finch
9 * Copyright (C) 1991 Massachusetts Institute of Technology
10 * (See the file INSTALL for full details.)
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation.
24 */
25
26 #ifndef ADNS_DLIST_H_INCLUDED
27 #define ADNS_DLIST_H_INCLUDED
28
29 #define LIST_INIT(list) ((list).head= (list).tail= 0)
30 #define LINK_INIT(link) ((link).next= (link).back= 0)
31
32 #define LIST_UNLINK_PART(list,node,part) \
33 do { \
34 if ((node)->part back) (node)->part back->part next= (node)->part next; \
35 else (list).head= (node)->part next; \
36 if ((node)->part next) (node)->part next->part back= (node)->part back; \
37 else (list).tail= (node)->part back; \
38 } while(0)
39
40 #define LIST_LINK_TAIL_PART(list,node,part) \
41 do { \
42 (node)->part next= 0; \
43 (node)->part back= (list).tail; \
44 if ((list).tail) (list).tail->part next= (node); \
45 else (list).head= (node); \
46 (list).tail= (node); \
47 } while(0)
48
49 #define LIST_UNLINK(list,node) LIST_UNLINK_PART(list,node,)
50 #define LIST_LINK_TAIL(list,node) LIST_LINK_TAIL_PART(list,node,)
51
52 #endif