1 /* $NetBSD: dlz_list.h,v 1.3 2014/12/10 04:37:55 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004, 2006, 2007, 2011-2013 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 1997-2002 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef DLZ_LIST_H 21 #define DLZ_LIST_H 1 22 23 #define DLZ_LIST(type) struct { type *head, *tail; } 24 #define DLZ_LIST_INIT(list) \ 25 do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0) 26 27 #define DLZ_LINK(type) struct { type *prev, *next; } 28 #define DLZ_LINK_INIT(elt, link) \ 29 do { \ 30 (elt)->link.prev = (void *)(-1); \ 31 (elt)->link.next = (void *)(-1); \ 32 } while (/*CONSTCOND*/0) 33 34 #define DLZ_LIST_HEAD(list) ((list).head) 35 #define DLZ_LIST_TAIL(list) ((list).tail) 36 37 #define DLZ_LIST_APPEND(list, elt, link) \ 38 do { \ 39 if ((list).tail != NULL) \ 40 (list).tail->link.next = (elt); \ 41 else \ 42 (list).head = (elt); \ 43 (elt)->link.prev = (list).tail; \ 44 (elt)->link.next = NULL; \ 45 (list).tail = (elt); \ 46 } while (/*CONSTCOND*/0) 47 48 #define DLZ_LIST_PREV(elt, link) ((elt)->link.prev) 49 #define DLZ_LIST_NEXT(elt, link) ((elt)->link.next) 50 51 #endif /* DLZ_LIST_H */ 52