1 /* 2 * Copyright 2004-2008, François Revol, <revol@free.fr>. 3 * Distributed under the terms of the MIT License. 4 */ 5 /* good old single linked list stuff */ 6 #ifndef _LISTS_H 7 #define _LISTS_H 8 9 #include <stddef.h> 10 11 typedef struct _slist_entry { 12 struct _slist_entry *next; 13 char id[0]; 14 } slist_entry; 15 16 typedef int (*slist_compare_func)(struct _slist_entry *item, void *id); 17 18 extern void slist_init(struct _slist_entry *item); 19 extern void slist_uninit(struct _slist_entry *item); 20 extern struct _slist_entry *slist_find(struct _slist_entry *head, slist_compare_func func, void *id); 21 extern status_t slist_insert_head(struct _slist_entry **head, struct _slist_entry *item); 22 extern struct _slist_entry *slist_dequeue_tail(struct _slist_entry **head); 23 extern status_t slist_remove(struct _slist_entry **head, struct _slist_entry *item); 24 extern struct _slist_entry *slist_next(struct _slist_entry *item); 25 26 #define LENT_TO_OBJ(_obtype, _sle, _moff) ((_obtype *)(((char *)(_sle)) - offsetof(_obtype, _moff))) 27 #define OBJ_TO_LENT(_obj, _member) (&((_obj)->_member)) 28 29 30 #endif /* _LISTS_H */ 31 32