]> git.sommitrealweird.co.uk Git - onak.git/blob - ll.h
cscvs to tla changeset 6
[onak.git] / ll.h
1 /*
2  * ll.h - various things of used for dealing with linked lists.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  */
8
9 #ifndef __LL_H__
10 #define __LL_H__
11
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;                  \
16         } else {                                                              \
17                 list->name##s = list->last_##name =                           \
18                         malloc(sizeof (*list->last_##name));                  \
19         }                                                                     \
20         memset(list->last_##name, 0, sizeof(*list->last_##name));             \
21         list->last_##name->packet = item;
22
23 #define ADD_PACKET_TO_LIST(list, item)                                        \
24         if (list != NULL) {                                                   \
25                 list->next = malloc(sizeof (*list));                          \
26                 list = list->next;                                            \
27         } else {                                                              \
28                 list = malloc(sizeof (*list));                                \
29         }                                                                     \
30         memset(list, 0, sizeof(*list));                                       \
31         list->packet = item;
32
33 /**
34  *      struct ll - A generic linked list structure.
35  *      @object: The object.
36  *      @next: A pointer to the next object.
37  */
38 struct ll {
39         void *object;
40         struct ll *next;
41 };
42
43 /**
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.
47  *
48  *      Returns a pointer to the head of the new list.
49  */
50 struct ll *lladd(struct ll *curll, void *object);
51
52 /**
53  *
54  */
55 struct ll *lldel(struct ll *curll, void *object,
56         int (*objectcmp) (const void *object1, const void *object2));
57
58 /**
59  *
60  */
61 struct ll *llfind(struct ll *curll, void *object,
62         int (*objectcmp) (const void *object1, const void *object2));
63
64 /**
65  *      llsize - Returns the number of elements in a linked list.
66  *      @curll: The linked list to count.
67  *
68  *      Counts the number of elements in a linked list.
69  */
70 unsigned long llsize(struct ll *curll);
71
72 #endif /* __LL_H__ */