--- trunk/mkinitrd-magellan/busybox/libbb/llist.c 2010/04/29 20:38:48 983 +++ trunk/mkinitrd-magellan/busybox/libbb/llist.c 2010/05/30 11:32:42 984 @@ -25,56 +25,38 @@ /* Add data to the end of the linked list. */ void FAST_FUNC llist_add_to_end(llist_t **list_head, void *data) { - llist_t *new_item = xmalloc(sizeof(llist_t)); - - new_item->data = data; - new_item->link = NULL; - - if (!*list_head) - *list_head = new_item; - else { - llist_t *tail = *list_head; - - while (tail->link) - tail = tail->link; - tail->link = new_item; - } + while (*list_head) + list_head = &(*list_head)->link; + *list_head = xzalloc(sizeof(llist_t)); + (*list_head)->data = data; + /*(*list_head)->link = NULL;*/ } /* Remove first element from the list and return it */ void* FAST_FUNC llist_pop(llist_t **head) { - void *data, *next; - - if (!*head) - return NULL; - - data = (*head)->data; - next = (*head)->link; - free(*head); - *head = next; + void *data = NULL; + llist_t *temp = *head; + if (temp) { + data = temp->data; + *head = temp->link; + free(temp); + } return data; } /* Unlink arbitrary given element from the list */ void FAST_FUNC llist_unlink(llist_t **head, llist_t *elm) { - llist_t *crt; - - if (!(elm && *head)) - return; - - if (elm == *head) { - *head = (*head)->link; + if (!elm) return; - } - - for (crt = *head; crt; crt = crt->link) { - if (crt->link == elm) { - crt->link = elm->link; - return; + while (*head) { + if (*head == elm) { + *head = (*head)->link; + break; } + head = &(*head)->link; } } @@ -104,3 +86,13 @@ } return rev; } + +llist_t* FAST_FUNC llist_find_str(llist_t *list, const char *str) +{ + while (list) { + if (strcmp(list->data, str) == 0) + break; + list = list->link; + } + return list; +}