Mercurial > hg > toybox
diff lib/llist.c @ 540:c2f39708a4c4
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.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 12 Mar 2012 00:25:40 -0500 |
parents | f1e9da78c5dd |
children | 1e8b9acdafeb |
line wrap: on
line diff
--- a/lib/llist.c Sat Mar 10 14:57:33 2012 -0600 +++ b/lib/llist.c Mon Mar 12 00:25:40 2012 -0500 @@ -35,18 +35,24 @@ 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; }