comparison 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
comparison
equal deleted inserted replaced
539:09135436042b 540:c2f39708a4c4
33 *llist = *next; 33 *llist = *next;
34 34
35 return (void *)next; 35 return (void *)next;
36 } 36 }
37 37
38 void dlist_add_nomalloc(struct double_list **list, struct double_list *new)
39 {
40 if (*list) {
41 new->next = *list;
42 new->prev = (*list)->prev;
43 (*list)->prev->next = new;
44 (*list)->prev = new;
45 } else *list = new->next = new->prev = new;
46 }
47
48
38 // Add an entry to the end of a doubly linked list 49 // Add an entry to the end of a doubly linked list
39 struct double_list *dlist_add(struct double_list **list, char *data) 50 struct double_list *dlist_add(struct double_list **list, char *data)
40 { 51 {
41 struct double_list *line = xmalloc(sizeof(struct double_list)); 52 struct double_list *new = xmalloc(sizeof(struct double_list));
42 53
43 line->data = data; 54 new->data = data;
44 if (*list) { 55 dlist_add_nomalloc(list, new);
45 line->next = *list;
46 line->prev = (*list)->prev;
47 (*list)->prev->next = line;
48 (*list)->prev = line;
49 } else *list = line->next = line->prev = line;
50 56
51 return line; 57 return new;
52 } 58 }