diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2007-02-04 20:32:38 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2007-02-04 20:32:38 +0000 |
| commit | d909d2345158e80ec2fee188ce3ca668850c5ee9 (patch) | |
| tree | f1764fe77f52fb927a63238a05ec473468d5d5ba /libbb | |
| parent | 7154b99c89f9598cafc0044008fe61eb202099dc (diff) | |
| download | busybox-w32-d909d2345158e80ec2fee188ce3ca668850c5ee9.tar.gz busybox-w32-d909d2345158e80ec2fee188ce3ca668850c5ee9.tar.bz2 busybox-w32-d909d2345158e80ec2fee188ce3ca668850c5ee9.zip | |
- indent
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/llist.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/libbb/llist.c b/libbb/llist.c index 8a74832ee..63c77fa9e 100644 --- a/libbb/llist.c +++ b/libbb/llist.c | |||
| @@ -14,37 +14,44 @@ | |||
| 14 | #include "libbb.h" | 14 | #include "libbb.h" |
| 15 | 15 | ||
| 16 | /* Add data to the start of the linked list. */ | 16 | /* Add data to the start of the linked list. */ |
| 17 | void llist_add_to(llist_t **old_head, void *data) | 17 | void llist_add_to(llist_t ** old_head, void *data) |
| 18 | { | 18 | { |
| 19 | llist_t *new_head = xmalloc(sizeof(llist_t)); | 19 | llist_t *new_head = xmalloc(sizeof(llist_t)); |
| 20 | |||
| 20 | new_head->data = data; | 21 | new_head->data = data; |
| 21 | new_head->link = *old_head; | 22 | new_head->link = *old_head; |
| 22 | *old_head = new_head; | 23 | *old_head = new_head; |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | /* Add data to the end of the linked list. */ | 26 | /* Add data to the end of the linked list. */ |
| 26 | void llist_add_to_end(llist_t **list_head, void *data) | 27 | void llist_add_to_end(llist_t ** list_head, void *data) |
| 27 | { | 28 | { |
| 28 | llist_t *new_item = xmalloc(sizeof(llist_t)); | 29 | llist_t *new_item = xmalloc(sizeof(llist_t)); |
| 30 | |||
| 29 | new_item->data = data; | 31 | new_item->data = data; |
| 30 | new_item->link = NULL; | 32 | new_item->link = NULL; |
| 31 | 33 | ||
| 32 | if (!*list_head) *list_head = new_item; | 34 | if (!*list_head) |
| 35 | *list_head = new_item; | ||
| 33 | else { | 36 | else { |
| 34 | llist_t *tail = *list_head; | 37 | llist_t *tail = *list_head; |
| 35 | while (tail->link) tail = tail->link; | 38 | |
| 39 | while (tail->link) | ||
| 40 | tail = tail->link; | ||
| 36 | tail->link = new_item; | 41 | tail->link = new_item; |
| 37 | } | 42 | } |
| 38 | } | 43 | } |
| 39 | 44 | ||
| 40 | /* Remove first element from the list and return it */ | 45 | /* Remove first element from the list and return it */ |
| 41 | void *llist_pop(llist_t **head) | 46 | void *llist_pop(llist_t ** head) |
| 42 | { | 47 | { |
| 43 | void *data; | 48 | void *data; |
| 44 | 49 | ||
| 45 | if(!*head) data = *head; | 50 | if (!*head) |
| 51 | data = *head; | ||
| 46 | else { | 52 | else { |
| 47 | void *next = (*head)->link; | 53 | void *next = (*head)->link; |
| 54 | |||
| 48 | data = (*head)->data; | 55 | data = (*head)->data; |
| 49 | free(*head); | 56 | free(*head); |
| 50 | *head = next; | 57 | *head = next; |
| @@ -55,21 +62,25 @@ void *llist_pop(llist_t **head) | |||
| 55 | 62 | ||
| 56 | /* Recursively free all elements in the linked list. If freeit != NULL | 63 | /* Recursively free all elements in the linked list. If freeit != NULL |
| 57 | * call it on each datum in the list */ | 64 | * call it on each datum in the list */ |
| 58 | void llist_free(llist_t *elm, void (*freeit)(void *data)) | 65 | void llist_free(llist_t * elm, void (*freeit) (void *data)) |
| 59 | { | 66 | { |
| 60 | while (elm) { | 67 | while (elm) { |
| 61 | void *data = llist_pop(&elm); | 68 | void *data = llist_pop(&elm); |
| 62 | if (freeit) freeit(data); | 69 | |
| 70 | if (freeit) | ||
| 71 | freeit(data); | ||
| 63 | } | 72 | } |
| 64 | } | 73 | } |
| 65 | 74 | ||
| 66 | /* Reverse list order. Useful since getopt32 saves option params | 75 | /* Reverse list order. Useful since getopt32 saves option params |
| 67 | * in reverse order */ | 76 | * in reverse order */ |
| 68 | llist_t* rev_llist(llist_t *list) | 77 | llist_t *rev_llist(llist_t * list) |
| 69 | { | 78 | { |
| 70 | llist_t *new = NULL; | 79 | llist_t *new = NULL; |
| 80 | |||
| 71 | while (list) { | 81 | while (list) { |
| 72 | llist_t *next = list->link; | 82 | llist_t *next = list->link; |
| 83 | |||
| 73 | list->link = new; | 84 | list->link = new; |
| 74 | new = list; | 85 | new = list; |
| 75 | list = next; | 86 | list = next; |
