From bee9eb1a9d04503d58070bd1946cc2c0538fcf95 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 29 Sep 2005 12:55:10 +0000 Subject: - rename llist_add_to.c to llist.c - move llist_add_to_end() from ifupdown.c to libbb/llist.c --- libbb/llist.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libbb/llist.c (limited to 'libbb/llist.c') diff --git a/libbb/llist.c b/libbb/llist.c new file mode 100644 index 000000000..cb87176c5 --- /dev/null +++ b/libbb/llist.c @@ -0,0 +1,43 @@ +#include +#include +#include "unarchive.h" +#include "libbb.h" + +#ifdef L_llist_add_to +extern llist_t *llist_add_to(llist_t *old_head, char *new_item) +{ + llist_t *new_head; + + new_head = xmalloc(sizeof(llist_t)); + new_head->data = new_item; + new_head->link = old_head; + + return (new_head); +} +#endif + +#ifdef L_llist_add_to_end +extern llist_t *llist_add_to_end(llist_t *list_head, char *data) +{ + llist_t *new_item, *tmp, *prev; + + new_item = xmalloc(sizeof(llist_t)); + new_item->data = data; + new_item->link = NULL; + + prev = NULL; + tmp = list_head; + while (tmp) { + prev = tmp; + tmp = tmp->link; + } + if (prev) { + prev->link = new_item; + } else { + list_head = new_item; + } + + return (list_head); +} +#endif + -- cgit v1.2.3