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 _LISTS2_H 7#define _LISTS2_H 8 9#ifdef __cplusplus 10extern "C" { 11#endif 12 13typedef int (*sll_compare_func)(const void *item, void *id); 14 15extern void *sll_find(long nextoff, void *head, sll_compare_func func, void *id); 16extern status_t sll_insert_head(long nextoff, void **head, void *item); 17extern status_t sll_insert_tail(long nextoff, void **head, void *item); 18extern void *sll_dequeue_tail(long nextoff, void **head); 19extern status_t sll_remove(long nextoff, void **head, void *item); 20extern void *sll_next(long nextoff, void *item); 21 22#define SLLPTROFF(type,item,nextp) ((typeof(item))(((char *)(item)) + offsetof(item, nextp))) 23#define SLLITEM2PTR(type,item,nextp) ((typeof(item))(((char *)(item)) + offsetof(item, nextp))) 24#define SLLPTR2ITEM(type,ptr,nextp) ((typeof(ptr))(((char *)(ptr)) - offsetof(ptr, nextp))) 25#define SLLNEXT(type,item,nextp) (*(typeof(item))(((char *)(item)) + offsetof(item, nextp))) 26 27#define SLL_FIND(_head,_nextp,_func,_with) (typeof(_head))sll_find(offsetof(typeof(*_head),_nextp), (void *)(_head), _func, _with) 28#define SLL_INSERT(_head,_nextp,_item) sll_insert_head(offsetof(typeof(*_head),_nextp), (void **)&(_head), _item) 29//#define SLL_INSERT_TAIL(_head,_nextp,_item) (typeof(_head))sll_insert_tail(offsetof(typeof(*_head),_nextp), (void **)&(_head), _item) 30#define SLL_INSERT_TAIL(_head,_nextp,_item) sll_insert_head(offsetof(typeof(*_head),_nextp), (void **)&(_head), _item) 31#define SLL_DEQUEUE(_head,_nextp) (typeof(_head))sll_dequeue_tail(offsetof(typeof(*_head),_nextp), (void **)&(_head)) 32#define SLL_REMOVE(_head,_nextp,_item) sll_remove(offsetof(typeof(*_head),_nextp), (void **)&(_head), _item) 33 34#ifdef __cplusplus 35} 36#endif 37 38#endif /* _LISTS2_H */ 39