blob: acd8601a6b9998c44719f3b9081218310954efe3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <ccan/list/list.h>
#include <ccan/tap/tap.h>
#include <ccan/list/list.c>
#include <stdbool.h>
#include <stdio.h>
struct child {
const char *name;
struct ccan_list_node list;
};
static bool children(const struct ccan_list_head *list)
{
return !ccan_list_empty(list);
}
static const struct child *first_child(const struct ccan_list_head *list)
{
return ccan_list_top(list, struct child, list);
}
static const struct child *last_child(const struct ccan_list_head *list)
{
return ccan_list_tail(list, struct child, list);
}
static void check_children(const struct ccan_list_head *list)
{
ccan_list_check(list, "bad child list");
}
static void print_children(const struct ccan_list_head *list)
{
const struct child *c;
ccan_list_for_each(list, c, list)
printf("%s\n", c->name);
}
int main(void)
{
CCAN_LIST_HEAD(h);
children(&h);
first_child(&h);
last_child(&h);
check_children(&h);
print_children(&h);
return 0;
}
|