aboutsummaryrefslogtreecommitdiff
path: root/lib/llist.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-11-13 17:14:08 -0600
committerRob Landley <rob@landley.net>2012-11-13 17:14:08 -0600
commit7aa651a6a4496d848f86de9b1e6b3a003256a01f (patch)
tree6995fb4b7cc2e90a6706b0239ebaf95d9dbab530 /lib/llist.c
parent571b0706cce45716126776d0ad0f6ac65f4586e3 (diff)
downloadtoybox-7aa651a6a4496d848f86de9b1e6b3a003256a01f.tar.gz
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/lib/llist.c b/lib/llist.c
index 4799db1c..9b6c2950 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -1,5 +1,4 @@
-/* vi: set sw=4 ts=4 :
- * llist.c - Linked list functions
+/* llist.c - Linked list functions
*
* Linked list structures have a next pointer as their first element.
*/
@@ -9,47 +8,47 @@
// Call a function (such as free()) on each element of a linked list.
void llist_traverse(void *list, void (*using)(void *data))
{
- while (list) {
- void *pop = llist_pop(&list);
- using(pop);
+ while (list) {
+ void *pop = llist_pop(&list);
+ using(pop);
- // End doubly linked list too.
- if (list==pop) break;
- }
+ // End doubly linked list too.
+ if (list==pop) break;
+ }
}
// Return the first item from the list, advancing the list (which must be called
// as &list)
void *llist_pop(void *list)
{
- // I'd use a void ** for the argument, and even accept the typecast in all
- // callers as documentation you need the &, except the stupid compiler
- // would then scream about type-punned pointers. Screw it.
- void **llist = (void **)list;
- void **next = (void **)*llist;
- *llist = *next;
-
- return (void *)next;
+ // I'd use a void ** for the argument, and even accept the typecast in all
+ // callers as documentation you need the &, except the stupid compiler
+ // would then scream about type-punned pointers. Screw it.
+ void **llist = (void **)list;
+ void **next = (void **)*llist;
+ *llist = *next;
+
+ 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;
+ 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 *new = xmalloc(sizeof(struct double_list));
+ struct double_list *new = xmalloc(sizeof(struct double_list));
- new->data = data;
- dlist_add_nomalloc(list, new);
+ new->data = data;
+ dlist_add_nomalloc(list, new);
- return new;
+ return new;
}