summaryrefslogtreecommitdiff
path: root/libbb/llist.c
diff options
context:
space:
mode:
authorRob Landley2006-05-26 23:44:51 +0000
committerRob Landley2006-05-26 23:44:51 +0000
commit8bb50782a5f0dd955a6fe18d381eb9322d1447e7 (patch)
treeb717c772c6fef53c34b723341a8c5b12ccb57902 /libbb/llist.c
parent5edc10275ec86f6ce6af97a8e2e5eeccb3a2e8cb (diff)
downloadbusybox-8bb50782a5f0dd955a6fe18d381eb9322d1447e7.zip
busybox-8bb50782a5f0dd955a6fe18d381eb9322d1447e7.tar.gz
Change llist_add_* to take the address of the list rather than returning the new
head, and change all the callers.
Diffstat (limited to 'libbb/llist.c')
-rw-r--r--libbb/llist.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/libbb/llist.c b/libbb/llist.c
index dd80436..fde25e8 100644
--- a/libbb/llist.c
+++ b/libbb/llist.c
@@ -14,37 +14,29 @@
#ifdef L_llist_add_to
/* Add data to the start of the linked list. */
-llist_t *llist_add_to(llist_t *old_head, void *data)
+void llist_add_to(llist_t **old_head, void *data)
{
- llist_t *new_head;
-
- new_head = xmalloc(sizeof(llist_t));
+ llist_t *new_head = xmalloc(sizeof(llist_t));
new_head->data = data;
- new_head->link = old_head;
-
- return (new_head);
+ new_head->link = *old_head;
+ *old_head = new_head;
}
#endif
#ifdef L_llist_add_to_end
/* Add data to the end of the linked list. */
-llist_t *llist_add_to_end(llist_t *list_head, void *data)
+void llist_add_to_end(llist_t **list_head, void *data)
{
- llist_t *new_item;
-
- new_item = xmalloc(sizeof(llist_t));
+ llist_t *new_item = xmalloc(sizeof(llist_t));
new_item->data = data;
new_item->link = NULL;
- if (list_head == NULL) {
- list_head = new_item;
- } else {
- llist_t *tail = list_head;
- while (tail->link)
- tail = tail->link;
+ if (!*list_head) *list_head = new_item;
+ else {
+ llist_t *tail = *list_head;
+ while (tail->link) tail = tail->link;
tail->link = new_item;
}
- return list_head;
}
#endif