2 * Doubly-linked list - test program
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/list.h"
24 static void dump_list(struct dl_list
*head
)
28 dl_list_for_each(t
, head
, struct test
, list
)
29 printf(" %d", t
->value
);
30 printf(" (len=%d%s)\n", dl_list_len(head
),
31 dl_list_empty(head
) ? " empty" : "");
34 int main(int argc
, char *argv
[])
43 for (i
= 0; i
< 5; i
++) {
44 t
= os_zalloc(sizeof(*t
));
48 dl_list_add(&head
, &t
->list
);
52 for (i
= 10; i
> 5; i
--) {
53 t
= os_zalloc(sizeof(*t
));
57 dl_list_add_tail(&head
, &t
->list
);
62 dl_list_for_each(t
, &head
, struct test
, list
)
65 printf("move: %d\n", t
->value
);
66 dl_list_del(&t
->list
);
67 dl_list_add(&head
, &t
->list
);
70 dl_list_for_each_safe(t
, tmp
, &head
, struct test
, list
) {
71 printf("delete: %d\n", t
->value
);
72 dl_list_del(&t
->list
);