| 1 |
#ifndef foollistfoo |
| 2 |
#define foollistfoo |
| 3 |
|
| 4 |
/*** |
| 5 |
This file is part of avahi. |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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 |
| 20 |
USA. |
| 21 |
***/ |
| 22 |
|
| 23 |
/** \file llist.h A simple macro based linked list implementation */ |
| 24 |
|
| 25 |
#include <assert.h> |
| 26 |
|
| 27 |
#include "cdecl.h" |
| 28 |
|
| 29 |
AVAHI_C_DECL_BEGIN |
| 30 |
|
| 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 |
| 34 |
|
| 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 |
| 37 |
|
| 38 |
/** Initialize the list's head */ |
| 39 |
#define AVAHI_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0) |
| 40 |
|
| 41 |
/** Initialize a list item */ |
| 42 |
#define AVAHI_LLIST_INIT(t,name,item) do { \ |
| 43 |
t *_item = (item); \ |
| 44 |
assert(_item); \ |
| 45 |
_item->name##_prev = _item->name##_next = NULL; \ |
| 46 |
} while(0) |
| 47 |
|
| 48 |
/** Prepend an item to the list */ |
| 49 |
#define AVAHI_LLIST_PREPEND(t,name,head,item) do { \ |
| 50 |
t **_head = &(head), *_item = (item); \ |
| 51 |
assert(_item); \ |
| 52 |
if ((_item->name##_next = *_head)) \ |
| 53 |
_item->name##_next->name##_prev = _item; \ |
| 54 |
_item->name##_prev = NULL; \ |
| 55 |
*_head = _item; \ |
| 56 |
} while (0) |
| 57 |
|
| 58 |
/** Remove an item from the list */ |
| 59 |
#define AVAHI_LLIST_REMOVE(t,name,head,item) do { \ |
| 60 |
t **_head = &(head), *_item = (item); \ |
| 61 |
assert(_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; \ |
| 66 |
else {\ |
| 67 |
assert(*_head == _item); \ |
| 68 |
*_head = _item->name##_next; \ |
| 69 |
} \ |
| 70 |
_item->name##_next = _item->name##_prev = NULL; \ |
| 71 |
} while(0) |
| 72 |
|
| 73 |
AVAHI_C_DECL_END |
| 74 |
|
| 75 |
#endif |