5 This file is part of avahi.
7 avahi is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 avahi is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with avahi; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 /** \file llist.h A simple macro based linked list implementation */
27 #include <avahi-common/cdecl.h>
31 /** The head of the linked list. Use this in the structure that shall
32 * contain the head of the linked list */
33 #define AVAHI_LLIST_HEAD(t,name) t *name
35 /** The pointers in the linked list's items. Use this in the item structure */
36 #define AVAHI_LLIST_FIELDS(t,name) t *name##_next, *name##_prev
38 /** Initialize the list's head */
39 #define AVAHI_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0)
41 /** Initialize a list item */
42 #define AVAHI_LLIST_INIT(t,name,item) do { \
45 _item->name##_prev = _item->name##_next = NULL; \
48 /** Prepend an item to the list */
49 #define AVAHI_LLIST_PREPEND(t,name,head,item) do { \
50 t **_head = &(head), *_item = (item); \
52 if ((_item->name##_next = *_head)) \
53 _item->name##_next->name##_prev = _item; \
54 _item->name##_prev = NULL; \
58 /** Remove an item from the list */
59 #define AVAHI_LLIST_REMOVE(t,name,head,item) do { \
60 t **_head = &(head), *_item = (item); \
62 if (_item->name##_next) \
63 _item->name##_next->name##_prev = _item->name##_prev; \
64 if (_item->name##_prev) \
65 _item->name##_prev->name##_next = _item->name##_next; \
67 assert(*_head == _item); \
68 *_head = _item->name##_next; \
70 _item->name##_next = _item->name##_prev = NULL; \