X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/fc0a36320874bea43b9fd73df0e0990bfd3b59cd..5e01d2924d4eec8915e93a2cae01217ae25ab4dc:/ll.c?ds=sidebyside diff --git a/ll.c b/ll.c index fc18fa5..2b00090 100644 --- a/ll.c +++ b/ll.c @@ -1,5 +1,6 @@ // L2TPNS Linked List Stuff -// $Id: ll.c,v 1.2 2004-03-05 00:09:03 fred_nerk Exp $ + +char const *cvs_id_ll = "$Id: ll.c,v 1.5 2004-08-13 00:02:50 fred_nerk Exp $"; #include #include @@ -15,127 +16,127 @@ linked_list *ll_init() { - return (linked_list *)calloc(sizeof(linked_list), 1); + return (linked_list *)calloc(sizeof(linked_list), 1); } void ll_done(linked_list *l) { - li *i = l->head, *n; + li *i = l->head, *n; - while (i) - { - n = i->next; - free(i); - i = n; - } + while (i) + { + n = i->next; + free(i); + i = n; + } - free(l); + free(l); } li *ll_push(linked_list *l, void *data) { - li *i; + li *i; - if (!l) return NULL; - if (!(i = (li *)calloc(sizeof(li), 1))) return NULL; + if (!l) return NULL; + if (!(i = (li *)calloc(sizeof(li), 1))) return NULL; - i->data = data; - i->next = NULL; - if (l->end) - l->end->next = i; - else - l->head = i; - l->end = i; + i->data = data; + i->next = NULL; + if (l->end) + l->end->next = i; + else + l->head = i; + l->end = i; - return i; + return i; } void *ll_pop(linked_list *l) { - li *i; - void *data; - - if (!l) return NULL; - if (!l->head) - return NULL; - - data = l->head->data; - i = l->head->next; - free(l->head); - l->head = i; - return data; + li *i; + void *data; + + if (!l) return NULL; + if (!l->head) + return NULL; + + data = l->head->data; + i = l->head->next; + free(l->head); + l->head = i; + return data; } void ll_iterate(linked_list *l, int(*func)(void *)) { - li *i; - if (!l || !func) return; - - for (i = l->head; i; i = i->next) - { - if (i->data) - if (!func(i)) - break; - } + li *i; + if (!l || !func) return; + + for (i = l->head; i; i = i->next) + { + if (i->data) + if (!func(i)) + break; + } } void ll_reset(linked_list *l) { - if (!l) return; - l->current = NULL; + if (!l) return; + l->current = NULL; } void *ll_next(linked_list *l) { - if (!l) return NULL; - if (!l->current) - l->current = l->head; - else - l->current = l->current->next; - if (!l->current) - return NULL; - return l->current->data; + if (!l) return NULL; + if (!l->current) + l->current = l->head; + else + l->current = l->current->next; + if (!l->current) + return NULL; + return l->current->data; } void ll_delete(linked_list *l, void *data) { - li *i = l->head, *p = NULL; + li *i = l->head, *p = NULL; - while (i) - { - if (i->data == data) + while (i) { - if (l->head == i) l->head = i->next; - if (l->end == i) l->end = i->next; - if (p) p->next = i->next; - free(i); - l->current = NULL; - return; + if (i->data == data) + { + if (l->head == i) l->head = i->next; + if (l->end == i) l->end = i->next; + if (p) p->next = i->next; + free(i); + l->current = NULL; + return; + } + p = i; + i = i->next; } - p = i; - i = i->next; - } } int ll_size(linked_list *l) { - int count = 0; - li *i; + int count = 0; + li *i; - if (!l) return 0; + if (!l) return 0; - for (i = l->head; i; i = i->next) - if (i->data) count++; + for (i = l->head; i; i = i->next) + if (i->data) count++; - return count; + return count; } int ll_contains(linked_list *l, void *search) { - li *i; - for (i = l->head; i; i = i->next) - if (i->data == search) - return 1; - return 0; + li *i; + for (i = l->head; i; i = i->next) + if (i->data == search) + return 1; + return 0; }