diff options
author | Rob Landley <rob@landley.net> | 2012-03-12 00:25:40 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-03-12 00:25:40 -0500 |
commit | 2c48247a01a19c709f693d649d8158bccb5fbf70 (patch) | |
tree | 53297abe89d56a745d1d9a9ddec161fc1adbae24 /lib/llist.c | |
parent | 9f4c1fd2de1b525b7638a79a8294f8d5b865bcc5 (diff) | |
download | toybox-2c48247a01a19c709f693d649d8158bccb5fbf70.tar.gz |
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.
Diffstat (limited to 'lib/llist.c')
-rw-r--r-- | lib/llist.c | 24 |
1 files changed, 15 insertions, 9 deletions
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; } |