]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/test-list.c
2 * Doubly-linked list - test program
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/list.h"
18 static void dump_list(struct dl_list
*head
)
22 dl_list_for_each(t
, head
, struct test
, list
)
23 printf(" %d", t
->value
);
24 printf(" (len=%d%s)\n", dl_list_len(head
),
25 dl_list_empty(head
) ? " empty" : "");
28 int main(int argc
, char *argv
[])
37 for (i
= 0; i
< 5; i
++) {
38 t
= os_zalloc(sizeof(*t
));
42 dl_list_add(&head
, &t
->list
);
46 for (i
= 10; i
> 5; i
--) {
47 t
= os_zalloc(sizeof(*t
));
51 dl_list_add_tail(&head
, &t
->list
);
56 dl_list_for_each(t
, &head
, struct test
, list
)
59 printf("move: %d\n", t
->value
);
60 dl_list_del(&t
->list
);
61 dl_list_add(&head
, &t
->list
);
64 dl_list_for_each_safe(t
, tmp
, &head
, struct test
, list
) {
65 printf("delete: %d\n", t
->value
);
66 dl_list_del(&t
->list
);