6 LIST_HEAD(listhead
, entry
) head
;
7 struct listhead
*headp
;
10 LIST_ENTRY(entry
) entries
;
16 const char *str
[] = { "this", "is", "a", "linked", "list" };
23 /* Populate list with str[] items */
24 for (i
= 0; i
< sizeof str
/ sizeof *str
; i
++) {
25 if ((n
= malloc(sizeof(struct entry
))) == NULL
) {
27 goto CLEANUP_AND_EXIT
;
32 LIST_INSERT_HEAD(&head
, n
, entries
);
34 LIST_INSERT_AFTER(np
, n
, entries
);
39 LIST_FOREACH(np
, &head
, entries
)
40 printf("%s\n", np
->str
);
43 /* Delete all elements */
44 while (LIST_FIRST(&head
) != NULL
)
45 LIST_REMOVE(LIST_FIRST(&head
), entries
);