blob: c57cdadc316769a410a9bf43c61bf204209c891e (
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 list_node list;
};
static bool children(const struct list_head *list)
{
return !list_empty(list);
}
static const struct child *first_child(const struct list_head *list)
{
return list_top(list, struct child, list);
}
static const struct child *last_child(const struct list_head *list)
{
return list_tail(list, struct child, list);
}
static void check_children(const struct list_head *list)
{
list_check(list, "bad child list");
}
static void print_children(const struct list_head *list)
{
const struct child *c;
list_for_each(list, c, list)
printf("%s\n", c->name);
}
int main(void)
{
LIST_HEAD(h);
children(&h);
first_child(&h);
last_child(&h);
check_children(&h);
print_children(&h);
return 0;
}
|