2 * ll.c - various things of used for dealing with linked lists.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2000-2002 Project Purple
15 struct ll *lladd(struct ll *curll, void *object)
19 if ((new = malloc(sizeof(struct ll))) == NULL) {
21 printf("Got NULL in lladd()\n");
31 struct ll *lldel(struct ll *curll, void *object,
32 int (*objectcmp) (const void *object1, const void *object2))
34 struct ll *cur = NULL;
35 struct ll *old = NULL;
37 assert(objectcmp != NULL);
42 } else if (!(*objectcmp)(cur->object, object)) {
48 while (cur->next != NULL) {
49 if (!(*objectcmp)(cur->next->object, object)) {
51 cur->next = cur->next->next;
59 struct ll *llfind(struct ll *curll, void *object,
60 int (*objectcmp) (const void *object1, const void *object2))
64 assert(objectcmp != NULL);
67 while (cur != NULL && (*objectcmp)(cur->object, object)) {
73 unsigned long llsize(struct ll *curll)
75 unsigned long count = 0;
77 while (curll != NULL) {
86 * llfree - Frees a linked list.
87 * @curll: The list to free.
88 * @objectfree: A pointer to a free function for the object.
90 * Walks through a list and free it. If a function is provided for
91 * objectfree then it's called for each element to free them, if it's NULL
92 * just the list is freed.
94 void llfree(struct ll *curll, void (*objectfree) (void *object))
98 while (curll != NULL) {
100 if (curll->object != NULL && objectfree != NULL) {
101 objectfree(curll->object);
102 curll->object = NULL;