Annotation of embedaddon/dhcp/includes/isc-dhcp/list.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC")
        !             3:  * Copyright (c) 1997-2003 by Internet Software Consortium
        !             4:  *
        !             5:  * Permission to use, copy, modify, and distribute this software for any
        !             6:  * purpose with or without fee is hereby granted, provided that the above
        !             7:  * copyright notice and this permission notice appear in all copies.
        !             8:  *
        !             9:  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
        !            10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            11:  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
        !            12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
        !            15:  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            16:  *
        !            17:  *   Internet Systems Consortium, Inc.
        !            18:  *   950 Charter Street
        !            19:  *   Redwood City, CA 94063
        !            20:  *   <info@isc.org>
        !            21:  *   https://www.isc.org/
        !            22:  */
        !            23: 
        !            24: #ifndef ISC_LIST_H
        !            25: #define ISC_LIST_H 1
        !            26: 
        !            27: #define ISC_LIST(type) struct { type *head, *tail; }
        !            28: #define ISC_LIST_INIT(list) \
        !            29:        do { (list).head = NULL; (list).tail = NULL; } while (0)
        !            30: 
        !            31: #define ISC_LINK(type) struct { type *prev, *next; }
        !            32: #define ISC_LINK_INIT(elt, link) \
        !            33:        do { \
        !            34:                (elt)->link.prev = (void *)(-1); \
        !            35:                (elt)->link.next = (void *)(-1); \
        !            36:        } while (0)
        !            37: #define ISC_LINK_LINKED(elt, link) ((elt)->link.prev != (void *)(-1))
        !            38: 
        !            39: #define ISC_LIST_HEAD(list) ((list).head)
        !            40: #define ISC_LIST_TAIL(list) ((list).tail)
        !            41: #define ISC_LIST_EMPTY(list) ((list).head == NULL)
        !            42: 
        !            43: #define ISC_LIST_PREPEND(list, elt, link) \
        !            44:        do { \
        !            45:                if ((list).head != NULL) \
        !            46:                        (list).head->link.prev = (elt); \
        !            47:                else \
        !            48:                        (list).tail = (elt); \
        !            49:                (elt)->link.prev = NULL; \
        !            50:                (elt)->link.next = (list).head; \
        !            51:                (list).head = (elt); \
        !            52:        } while (0)
        !            53: 
        !            54: #define ISC_LIST_APPEND(list, elt, link) \
        !            55:        do { \
        !            56:                if ((list).tail != NULL) \
        !            57:                        (list).tail->link.next = (elt); \
        !            58:                else \
        !            59:                        (list).head = (elt); \
        !            60:                (elt)->link.prev = (list).tail; \
        !            61:                (elt)->link.next = NULL; \
        !            62:                (list).tail = (elt); \
        !            63:        } while (0)
        !            64: 
        !            65: #define ISC_LIST_UNLINK(list, elt, link) \
        !            66:        do { \
        !            67:                if ((elt)->link.next != NULL) \
        !            68:                        (elt)->link.next->link.prev = (elt)->link.prev; \
        !            69:                else \
        !            70:                        (list).tail = (elt)->link.prev; \
        !            71:                if ((elt)->link.prev != NULL) \
        !            72:                        (elt)->link.prev->link.next = (elt)->link.next; \
        !            73:                else \
        !            74:                        (list).head = (elt)->link.next; \
        !            75:                (elt)->link.prev = (void *)(-1); \
        !            76:                (elt)->link.next = (void *)(-1); \
        !            77:        } while (0)
        !            78: 
        !            79: #define ISC_LIST_PREV(elt, link) ((elt)->link.prev)
        !            80: #define ISC_LIST_NEXT(elt, link) ((elt)->link.next)
        !            81: 
        !            82: #define ISC_LIST_INSERTBEFORE(list, before, elt, link) \
        !            83:        do { \
        !            84:                if ((before)->link.prev == NULL) \
        !            85:                        ISC_LIST_PREPEND(list, elt, link); \
        !            86:                else { \
        !            87:                        (elt)->link.prev = (before)->link.prev; \
        !            88:                        (before)->link.prev = (elt); \
        !            89:                        (elt)->link.prev->link.next = (elt); \
        !            90:                        (elt)->link.next = (before); \
        !            91:                } \
        !            92:        } while (0)
        !            93: 
        !            94: #define ISC_LIST_INSERTAFTER(list, after, elt, link) \
        !            95:        do { \
        !            96:                if ((after)->link.next == NULL) \
        !            97:                        ISC_LIST_APPEND(list, elt, link); \
        !            98:                else { \
        !            99:                        (elt)->link.next = (after)->link.next; \
        !           100:                        (after)->link.next = (elt); \
        !           101:                        (elt)->link.next->link.prev = (elt); \
        !           102:                        (elt)->link.prev = (after); \
        !           103:                } \
        !           104:        } while (0)
        !           105: 
        !           106: #define ISC_LIST_APPENDLIST(list1, list2, link) \
        !           107:        do { \
        !           108:                if (ISC_LIST_EMPTY(list1)) \
        !           109:                        (list1) = (list2); \
        !           110:                else if (!ISC_LIST_EMPTY(list2)) { \
        !           111:                        (list1).tail->link.next = (list2).head; \
        !           112:                        (list2).head->link.prev = (list1).tail; \
        !           113:                        (list1).tail = (list2).tail; \
        !           114:                        (list2).head = NULL; \
        !           115:                        (list2).tail = NULL; \
        !           116:                } \
        !           117:        } while (0)
        !           118: 
        !           119: #define ISC_LIST_ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link)
        !           120: #define ISC_LIST_DEQUEUE(list, elt, link) ISC_LIST_UNLINK(list, elt, link)
        !           121: 
        !           122: #endif /* ISC_LIST_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>