1*7304104dSAndroid Build Coastguard Worker /* Copyright (C) 2001, 2002, 2003 Red Hat, Inc. 2*7304104dSAndroid Build Coastguard Worker This file is part of elfutils. 3*7304104dSAndroid Build Coastguard Worker Written by Ulrich Drepper <[email protected]>, 2001. 4*7304104dSAndroid Build Coastguard Worker 5*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify 6*7304104dSAndroid Build Coastguard Worker it under the terms of either 7*7304104dSAndroid Build Coastguard Worker 8*7304104dSAndroid Build Coastguard Worker * the GNU Lesser General Public License as published by the Free 9*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 3 of the License, or (at 10*7304104dSAndroid Build Coastguard Worker your option) any later version 11*7304104dSAndroid Build Coastguard Worker 12*7304104dSAndroid Build Coastguard Worker or 13*7304104dSAndroid Build Coastguard Worker 14*7304104dSAndroid Build Coastguard Worker * the GNU General Public License as published by the Free 15*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 2 of the License, or (at 16*7304104dSAndroid Build Coastguard Worker your option) any later version 17*7304104dSAndroid Build Coastguard Worker 18*7304104dSAndroid Build Coastguard Worker or both in parallel, as here. 19*7304104dSAndroid Build Coastguard Worker 20*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but 21*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of 22*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23*7304104dSAndroid Build Coastguard Worker General Public License for more details. 24*7304104dSAndroid Build Coastguard Worker 25*7304104dSAndroid Build Coastguard Worker You should have received copies of the GNU General Public License and 26*7304104dSAndroid Build Coastguard Worker the GNU Lesser General Public License along with this program. If 27*7304104dSAndroid Build Coastguard Worker not, see <http://www.gnu.org/licenses/>. */ 28*7304104dSAndroid Build Coastguard Worker 29*7304104dSAndroid Build Coastguard Worker #ifndef LIST_H 30*7304104dSAndroid Build Coastguard Worker #define LIST_H 1 31*7304104dSAndroid Build Coastguard Worker 32*7304104dSAndroid Build Coastguard Worker /* Add element to the end of a circular, double-linked list. */ 33*7304104dSAndroid Build Coastguard Worker #define CDBL_LIST_ADD_REAR(first, newp) \ 34*7304104dSAndroid Build Coastguard Worker do { \ 35*7304104dSAndroid Build Coastguard Worker __typeof (newp) _newp = (newp); \ 36*7304104dSAndroid Build Coastguard Worker assert (_newp->next == NULL); \ 37*7304104dSAndroid Build Coastguard Worker assert (_newp->previous == NULL); \ 38*7304104dSAndroid Build Coastguard Worker if (unlikely ((first) == NULL)) \ 39*7304104dSAndroid Build Coastguard Worker (first) = _newp->next = _newp->previous = _newp; \ 40*7304104dSAndroid Build Coastguard Worker else \ 41*7304104dSAndroid Build Coastguard Worker { \ 42*7304104dSAndroid Build Coastguard Worker _newp->next = (first); \ 43*7304104dSAndroid Build Coastguard Worker _newp->previous = (first)->previous; \ 44*7304104dSAndroid Build Coastguard Worker _newp->previous->next = _newp->next->previous = _newp; \ 45*7304104dSAndroid Build Coastguard Worker } \ 46*7304104dSAndroid Build Coastguard Worker } while (0) 47*7304104dSAndroid Build Coastguard Worker 48*7304104dSAndroid Build Coastguard Worker /* Remove element from circular, double-linked list. */ 49*7304104dSAndroid Build Coastguard Worker #define CDBL_LIST_DEL(first, elem) \ 50*7304104dSAndroid Build Coastguard Worker do { \ 51*7304104dSAndroid Build Coastguard Worker __typeof (elem) _elem = (elem); \ 52*7304104dSAndroid Build Coastguard Worker /* Check whether the element is indeed on the list. */ \ 53*7304104dSAndroid Build Coastguard Worker assert (first != NULL && _elem != NULL \ 54*7304104dSAndroid Build Coastguard Worker && (first != elem \ 55*7304104dSAndroid Build Coastguard Worker || ({ __typeof (elem) _runp = first->next; \ 56*7304104dSAndroid Build Coastguard Worker while (_runp != first) \ 57*7304104dSAndroid Build Coastguard Worker if (_runp == _elem) \ 58*7304104dSAndroid Build Coastguard Worker break; \ 59*7304104dSAndroid Build Coastguard Worker else \ 60*7304104dSAndroid Build Coastguard Worker _runp = _runp->next; \ 61*7304104dSAndroid Build Coastguard Worker _runp == _elem; }))); \ 62*7304104dSAndroid Build Coastguard Worker if (unlikely (_elem->next == _elem)) \ 63*7304104dSAndroid Build Coastguard Worker first = NULL; \ 64*7304104dSAndroid Build Coastguard Worker else \ 65*7304104dSAndroid Build Coastguard Worker { \ 66*7304104dSAndroid Build Coastguard Worker _elem->next->previous = _elem->previous; \ 67*7304104dSAndroid Build Coastguard Worker _elem->previous->next = _elem->next; \ 68*7304104dSAndroid Build Coastguard Worker if (unlikely (first == _elem)) \ 69*7304104dSAndroid Build Coastguard Worker first = _elem->next; \ 70*7304104dSAndroid Build Coastguard Worker } \ 71*7304104dSAndroid Build Coastguard Worker assert ((_elem->next = _elem->previous = NULL, 1)); \ 72*7304104dSAndroid Build Coastguard Worker } while (0) 73*7304104dSAndroid Build Coastguard Worker 74*7304104dSAndroid Build Coastguard Worker 75*7304104dSAndroid Build Coastguard Worker /* Add element to the front of a single-linked list. */ 76*7304104dSAndroid Build Coastguard Worker #define SNGL_LIST_PUSH(first, newp) \ 77*7304104dSAndroid Build Coastguard Worker do { \ 78*7304104dSAndroid Build Coastguard Worker __typeof (newp) _newp = (newp); \ 79*7304104dSAndroid Build Coastguard Worker assert (_newp->next == NULL); \ 80*7304104dSAndroid Build Coastguard Worker _newp->next = first; \ 81*7304104dSAndroid Build Coastguard Worker first = _newp; \ 82*7304104dSAndroid Build Coastguard Worker } while (0) 83*7304104dSAndroid Build Coastguard Worker 84*7304104dSAndroid Build Coastguard Worker 85*7304104dSAndroid Build Coastguard Worker /* Add element to the rear of a circular single-linked list. */ 86*7304104dSAndroid Build Coastguard Worker #define CSNGL_LIST_ADD_REAR(first, newp) \ 87*7304104dSAndroid Build Coastguard Worker do { \ 88*7304104dSAndroid Build Coastguard Worker __typeof (newp) _newp = (newp); \ 89*7304104dSAndroid Build Coastguard Worker assert (_newp->next == NULL); \ 90*7304104dSAndroid Build Coastguard Worker if (unlikely ((first) == NULL)) \ 91*7304104dSAndroid Build Coastguard Worker (first) = _newp->next = _newp; \ 92*7304104dSAndroid Build Coastguard Worker else \ 93*7304104dSAndroid Build Coastguard Worker { \ 94*7304104dSAndroid Build Coastguard Worker _newp->next = (first)->next; \ 95*7304104dSAndroid Build Coastguard Worker (first) = (first)->next = _newp; \ 96*7304104dSAndroid Build Coastguard Worker } \ 97*7304104dSAndroid Build Coastguard Worker } while (0) 98*7304104dSAndroid Build Coastguard Worker 99*7304104dSAndroid Build Coastguard Worker 100*7304104dSAndroid Build Coastguard Worker #endif /* list.h */ 101