Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/llist.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/llist.c
r1765 r2725 5 5 * Copyright (C) 2003 Glenn McGrath 6 6 * Copyright (C) 2005 Vladimir Oleynik 7 * Copyright (C) 2005 Bernhard Fischer7 * Copyright (C) 2005 Bernhard Reutner-Fischer 8 8 * Copyright (C) 2006 Rob Landley <rob@landley.net> 9 9 * 10 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.10 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 11 11 */ 12 12 … … 14 14 15 15 /* Add data to the start of the linked list. */ 16 void llist_add_to(llist_t **old_head, void *data)16 void FAST_FUNC llist_add_to(llist_t **old_head, void *data) 17 17 { 18 18 llist_t *new_head = xmalloc(sizeof(llist_t)); … … 24 24 25 25 /* Add data to the end of the linked list. */ 26 void llist_add_to_end(llist_t **list_head, void *data)26 void FAST_FUNC llist_add_to_end(llist_t **list_head, void *data) 27 27 { 28 llist_t *new_item = xmalloc(sizeof(llist_t)); 29 30 new_item->data = data; 31 new_item->link = NULL; 32 33 if (!*list_head) 34 *list_head = new_item; 35 else { 36 llist_t *tail = *list_head; 37 38 while (tail->link) 39 tail = tail->link; 40 tail->link = new_item; 41 } 28 while (*list_head) 29 list_head = &(*list_head)->link; 30 *list_head = xzalloc(sizeof(llist_t)); 31 (*list_head)->data = data; 32 /*(*list_head)->link = NULL;*/ 42 33 } 43 34 44 35 /* Remove first element from the list and return it */ 45 void *llist_pop(llist_t **head)36 void* FAST_FUNC llist_pop(llist_t **head) 46 37 { 47 void *data, *next; 38 void *data = NULL; 39 llist_t *temp = *head; 48 40 49 if (!*head) 50 return NULL; 51 52 data = (*head)->data; 53 next = (*head)->link; 54 free(*head); 55 *head = next; 56 41 if (temp) { 42 data = temp->data; 43 *head = temp->link; 44 free(temp); 45 } 57 46 return data; 58 47 } 59 48 60 49 /* Unlink arbitrary given element from the list */ 61 void llist_unlink(llist_t **head, llist_t *elm)50 void FAST_FUNC llist_unlink(llist_t **head, llist_t *elm) 62 51 { 63 llist_t *crt; 64 65 if (!(elm && *head)) 52 if (!elm) 66 53 return; 67 68 if (elm == *head) { 69 *head = (*head)->link; 70 return; 71 } 72 73 for (crt = *head; crt; crt = crt->link) { 74 if (crt->link == elm) { 75 crt->link = elm->link; 76 return; 54 while (*head) { 55 if (*head == elm) { 56 *head = (*head)->link; 57 break; 77 58 } 59 head = &(*head)->link; 78 60 } 79 61 } … … 81 63 /* Recursively free all elements in the linked list. If freeit != NULL 82 64 * call it on each datum in the list */ 83 void llist_free(llist_t *elm, void (*freeit) (void *data))65 void FAST_FUNC llist_free(llist_t *elm, void (*freeit) (void *data)) 84 66 { 85 67 while (elm) { … … 91 73 } 92 74 93 #ifdef UNUSED94 75 /* Reverse list order. */ 95 llist_t *llist_rev(llist_t *list)76 llist_t* FAST_FUNC llist_rev(llist_t *list) 96 77 { 97 78 llist_t *rev = NULL; … … 106 87 return rev; 107 88 } 108 #endif 89 90 llist_t* FAST_FUNC llist_find_str(llist_t *list, const char *str) 91 { 92 while (list) { 93 if (strcmp(list->data, str) == 0) 94 break; 95 list = list->link; 96 } 97 return list; 98 }
Note:
See TracChangeset
for help on using the changeset viewer.