13 * list_init() - statically initialise a list object.
14 * list_create() - create a new linked list object.
15 * list_append() - append an item to the head of the list.
16 * list_prepend() - prepend an item to the tail of the list.
17 * list_clear() - clear (free) all nodes in a list.
18 * list_free() - free memory associated with list object and its nodes.
21 /* {{{ int8_t list_init() */
23 list_init (list_t
*list
)
33 * Could do some leak checking here...
44 /* {{{ list_t *list_create() */
50 list
= smalloc(sizeof(*list
));
51 if (list_init(list
) < 0)
61 /* {{{ int8_t list_append () */
63 list_append (list_t
*list
, void *data
)
65 list_node_t
*new = NULL
;
74 new = smalloc(sizeof(*new));
80 * Consistency checks...
82 assert(list
->head
&& !list
->tail
);
83 assert(!list
->head
&& list
->tail
);
88 list
->tail
= list
->head
;
92 new->prev
= list
->tail
;
100 /* {{{ int8_t list_prepend() */
102 list_prepend (list_t
*list
, void *data
)
104 list_node_t
*new = NULL
;
106 assert(list
&& data
);
113 new = smalloc(sizeof(*new));
119 * Consistency checks...
121 assert(list
->head
&& !list
->tail
);
122 assert(!list
->head
&& list
->tail
);
127 list
->tail
= list
->head
;
131 new->next
= list
->head
;
139 /* {{{ void list_clear() */
141 list_clear (list_t
*list
)
143 list_node_t
*cur
= NULL
;
144 list_node_t
*next
= NULL
;
147 if (!list
|| !list
->head
)
160 /* {{{ void list_free() */
162 list_free (list_t
*list
)
175 * vim: ts=8 sw=8 noet fdm=marker tw=80