2 * ll.h - various things of used for dealing with linked lists.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
12 #define ADD_PACKET_TO_LIST_END(list, name, item) \
13 if (list->name##s != NULL) { \
14 list->last_##name->next = malloc(sizeof (*list->last_##name));\
15 list->last_##name = list->last_##name->next; \
17 list->name##s = list->last_##name = \
18 malloc(sizeof (*list->last_##name)); \
20 memset(list->last_##name, 0, sizeof(*list->last_##name)); \
21 list->last_##name->packet = item;
23 #define ADD_PACKET_TO_LIST(list, item) \
25 list->next = malloc(sizeof (*list)); \
28 list = malloc(sizeof (*list)); \
30 memset(list, 0, sizeof(*list)); \
34 * struct ll - A generic linked list structure.
35 * @object: The object.
36 * @next: A pointer to the next object.
44 * lladd - Add an item to a linked list.
45 * @curll: The list to add to. Can be NULL to create a new list.
46 * @object: The object to add.
48 * Returns a pointer to the head of the new list.
50 struct ll *lladd(struct ll *curll, void *object);
55 struct ll *lldel(struct ll *curll, void *object,
56 int (*objectcmp) (const void *object1, const void *object2));
61 struct ll *llfind(struct ll *curll, void *object,
62 int (*objectcmp) (const void *object1, const void *object2));
65 * llsize - Returns the number of elements in a linked list.
66 * @curll: The linked list to count.
68 * Counts the number of elements in a linked list.
70 unsigned long llsize(struct ll *curll);