2 * ll.c - various things of used for dealing with linked lists.
4 * Copyright 2000-2004 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <https://www.gnu.org/licenses/>.
25 struct ll *lladd(struct ll *curll, void *object)
29 if ((new = malloc(sizeof(struct ll))) == NULL) {
31 printf("Got NULL in lladd()\n");
41 struct ll *lladdend(struct ll *curll, void *object)
46 if ((new = malloc(sizeof(struct ll))) == NULL) {
55 while (cur->next != NULL) {
66 struct ll *lldel(struct ll *curll, void *object,
67 int (*objectcmp) (const void *object1, const void *object2))
69 struct ll *cur = NULL;
70 struct ll *old = NULL;
72 assert(objectcmp != NULL);
77 } else if (!(*objectcmp)(cur->object, object)) {
83 while (cur->next != NULL) {
84 if (!(*objectcmp)(cur->next->object, object)) {
86 cur->next = cur->next->next;
94 struct ll *llfind(struct ll *curll, void *object,
95 int (*objectcmp) (const void *object1, const void *object2))
99 assert(objectcmp != NULL);
102 while (cur != NULL && (*objectcmp)(cur->object, object)) {
108 unsigned long llsize(struct ll *curll)
110 unsigned long count = 0;
112 while (curll != NULL) {
120 void llfree(struct ll *curll, void (*objectfree) (void *object))
124 while (curll != NULL) {
125 nextll = curll->next;
126 if (curll->object != NULL && objectfree != NULL) {
127 objectfree(curll->object);
128 curll->object = NULL;