michael@0: /* -*- Mode: C; tab-width: 8; c-basic-offset: 8; indent-tabs-mode: t -*- */ michael@0: /* vim:set softtabstop=8 shiftwidth=8 noet: */ michael@0: /*- michael@0: * Copyright (C) the Mozilla Foundation. michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice(s), this list of conditions and the following disclaimer as michael@0: * the first lines of this file unmodified other than the possible michael@0: * addition of one or more copyright notices. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice(s), this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the michael@0: * distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY michael@0: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR michael@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR michael@0: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, michael@0: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE michael@0: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, michael@0: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: *******************************************************************************/ michael@0: michael@0: #ifndef linkedlist_h__ michael@0: #define linkedlist_h__ michael@0: michael@0: #include michael@0: michael@0: typedef struct LinkedList_s LinkedList; michael@0: michael@0: struct LinkedList_s { michael@0: LinkedList *next; michael@0: LinkedList *prev; michael@0: }; michael@0: michael@0: /* Convert from LinkedList* to foo*. */ michael@0: #define LinkedList_Get(e, type, prop) \ michael@0: (type*)((char*)(e) - offsetof(type, prop)) michael@0: michael@0: /* Insert |e| at the beginning of |l|. */ michael@0: void LinkedList_InsertHead(LinkedList *l, LinkedList *e) michael@0: { michael@0: e->next = l; michael@0: e->prev = l->prev; michael@0: e->next->prev = e; michael@0: e->prev->next = e; michael@0: } michael@0: michael@0: void LinkedList_Remove(LinkedList *e) michael@0: { michael@0: e->prev->next = e->next; michael@0: e->next->prev = e->prev; michael@0: e->next = e; michael@0: e->prev = e; michael@0: } michael@0: michael@0: bool LinkedList_IsEmpty(LinkedList *e) michael@0: { michael@0: return e->next == e; michael@0: } michael@0: michael@0: void LinkedList_Init(LinkedList *e) michael@0: { michael@0: e->next = e; michael@0: e->prev = e; michael@0: } michael@0: michael@0: #endif