aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-04 20:32:38 +0000
committeraldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-04 20:32:38 +0000
commite10b4620f8465a77785e7ee9e9a479e07b00c491 (patch)
treef1764fe77f52fb927a63238a05ec473468d5d5ba
parent040009e2837b66213641883b55683c40e79845ce (diff)
downloadbusybox-w32-e10b4620f8465a77785e7ee9e9a479e07b00c491.tar.gz
busybox-w32-e10b4620f8465a77785e7ee9e9a479e07b00c491.tar.bz2
busybox-w32-e10b4620f8465a77785e7ee9e9a479e07b00c491.zip
- indent
git-svn-id: svn://busybox.net/trunk/busybox@17770 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/llist.c29
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. */
17void llist_add_to(llist_t **old_head, void *data) 17void 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. */
26void llist_add_to_end(llist_t **list_head, void *data) 27void 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 */
41void *llist_pop(llist_t **head) 46void *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 */
58void llist_free(llist_t *elm, void (*freeit)(void *data)) 65void 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 */
68llist_t* rev_llist(llist_t *list) 77llist_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;