2 gcc linkedlist.c -o linkedlist -Wall -W -Wextra -ansi -pedantic */
9 LIST_HEAD(listhead
, entry
) head
;
10 struct listhead
*headp
;
13 LIST_ENTRY(entry
) entries
;
19 const char *str
[] = { "this", "is", "a", "linked", "list" };
26 /* Populate list with str[] items */
27 for (i
= 0; i
< sizeof str
/ sizeof *str
; i
++) {
28 if ((n
= malloc(sizeof(struct entry
))) == NULL
) {
30 goto CLEANUP_AND_EXIT
;
35 LIST_INSERT_HEAD(&head
, n
, entries
);
37 LIST_INSERT_AFTER(np
, n
, entries
);
42 LIST_FOREACH(np
, &head
, entries
)
43 printf("%s\n", np
->str
);
46 /* Delete all elements */
47 while (LIST_FIRST(&head
) != NULL
)
48 LIST_REMOVE(LIST_FIRST(&head
), entries
);