2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
9 void *sll_find(long nextoff
, void *head
, sll_compare_func func
, void *id
)
18 p
= sll_next(nextoff
, p
);
20 dprintf("sll_find: WARNING: 5000 nodes to search ??? looks more of a loop.\n");
27 status_t
sll_insert_head(long nextoff
, void **head
, void *item
)
30 if (head
== NULL
|| item
== NULL
)
34 *(void **)(((char *)item
)+nextoff
) = next
;
39 status_t
sll_insert_tail(long nextoff
, void **head
, void *item
)
41 void *p
, *next
= NULL
;
42 if (head
== NULL
|| item
== NULL
)
45 if (*(void **)(((char *)item
)+nextoff
)) {
46 dprintf("sll_insert_tail: WARNING: %p->next NOT NULL\n", item
);
47 *(void **)(((char *)item
)+nextoff
) = NULL
;
55 while (sll_next(nextoff
, p
))
56 p
= sll_next(nextoff
, p
);
57 *(void **)(((char *)p
)+nextoff
) = item
;
61 void *sll_dequeue_tail(long nextoff
, void **head
)
65 if (head
== NULL
|| *head
== NULL
)
69 while (sll_next(nextoff
, curr
)) {
70 prev
= (void **)(((char *)curr
)+nextoff
);
71 curr
= sll_next(nextoff
, curr
);
77 status_t
sll_remove(long nextoff
, void **head
, void *item
)
81 if (head
== NULL
|| *head
== NULL
|| item
== NULL
)
85 while (prev
&& curr
) {
87 *prev
= sll_next(nextoff
, curr
);
88 *(void **)(((char *)item
)+nextoff
) = NULL
;
91 prev
= (void **)(((char *)curr
)+nextoff
);
92 curr
= sll_next(nextoff
, curr
);
97 void *sll_next(long nextoff
, void *item
)
102 next
= *(void **)(((char *)item
)+nextoff
);