From 2c48247a01a19c709f693d649d8158bccb5fbf70 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 12 Mar 2012 00:25:40 -0500 Subject: Redo tail to use optargs and optionally support lseek. Add support to optargs and llist.c, plus add a test suite entry. Still no -f support though. --- lib/llist.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index c6e7da33..8588721b 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -35,18 +35,24 @@ void *llist_pop(void *list) return (void *)next; } +void dlist_add_nomalloc(struct double_list **list, struct double_list *new) +{ + if (*list) { + new->next = *list; + new->prev = (*list)->prev; + (*list)->prev->next = new; + (*list)->prev = new; + } else *list = new->next = new->prev = new; +} + + // Add an entry to the end of a doubly linked list struct double_list *dlist_add(struct double_list **list, char *data) { - struct double_list *line = xmalloc(sizeof(struct double_list)); + struct double_list *new = xmalloc(sizeof(struct double_list)); - line->data = data; - if (*list) { - line->next = *list; - line->prev = (*list)->prev; - (*list)->prev->next = line; - (*list)->prev = line; - } else *list = line->next = line->prev = line; + new->data = data; + dlist_add_nomalloc(list, new); - return line; + return new; } -- cgit v1.2.3