list.h (1050B)
1 /* Copyright 1998-1999, Brian J. Swetland. All rights reserved. 2 ** Distributed under the terms of the OpenBLT License 3 */ 4 5 #ifndef _LIST_H 6 #define _LIST_H 7 8 #include "types.h" 9 10 struct __list_t 11 { 12 node_t *next; /* aka head */ 13 node_t *prev; /* aka tail */ 14 uint32 count; 15 }; 16 17 /* generic or template dlinklist node */ 18 struct __node_t 19 { 20 node_t *next; 21 node_t *prev; 22 void *data; 23 }; 24 25 void list_init(list_t *list); 26 27 /* these functions allocate and destroy node_t's to store the items */ 28 void list_add_head(list_t *list, void *data); 29 void list_add_tail(list_t *list, void *data); 30 void *list_peek_head(list_t *list); 31 void *list_peek_tail(list_t *list); 32 void *list_remove_head(list_t *list); 33 void *list_remove_tail(list_t *list); 34 int list_remove(list_t *list, void *data); 35 36 /* these functions are for items that "own" the node_t */ 37 void list_attach_head(list_t *list, node_t *node); 38 void list_attach_tail(list_t *list, node_t *node); 39 void *list_detach_head(list_t *list); 40 void *list_detach_tail(list_t *list); 41 int list_detach(list_t *list, void *data); 42 43 #endif