1 // L2TPNS Linked List Stuff
3 char const *cvs_id_ll
= "$Id: ll.c,v 1.6 2004-11-18 08:12:55 bodea Exp $";
12 #include <arpa/inet.h>
17 linked_list
*ll_init()
19 return (linked_list
*)calloc(sizeof(linked_list
), 1);
22 void ll_done(linked_list
*l
)
36 li
*ll_push(linked_list
*l
, void *data
)
41 if (!(i
= (li
*)calloc(sizeof(li
), 1))) return NULL
;
54 void *ll_pop(linked_list
*l
)
70 void ll_iterate(linked_list
*l
, int(*func
)(void *))
73 if (!l
|| !func
) return;
75 for (i
= l
->head
; i
; i
= i
->next
)
77 if (i
->data
&& !func(i
->data
))
82 void ll_reset(linked_list
*l
)
88 void *ll_next(linked_list
*l
)
94 l
->current
= l
->current
->next
;
97 return l
->current
->data
;
100 void ll_delete(linked_list
*l
, void *data
)
102 li
*i
= l
->head
, *p
= NULL
;
108 if (l
->head
== i
) l
->head
= i
->next
;
109 if (l
->end
== i
) l
->end
= p
;
110 if (p
) p
->next
= i
->next
;
120 int ll_size(linked_list
*l
)
127 for (i
= l
->head
; i
; i
= i
->next
)
128 if (i
->data
) count
++;
133 int ll_contains(linked_list
*l
, void *search
)
136 for (i
= l
->head
; i
; i
= i
->next
)
137 if (i
->data
== search
)