1 /* Copyright (C) 2001, 2002, 2003 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
32 /* Add element to the end of a circular, double-linked list. */
33 #define CDBL_LIST_ADD_REAR(first, newp) \
35 __typeof (newp) _newp = (newp); \
36 assert (_newp->next == NULL); \
37 assert (_newp->previous == NULL); \
38 if (unlikely ((first) == NULL)) \
39 (first) = _newp->next = _newp->previous = _newp; \
42 _newp->next = (first); \
43 _newp->previous = (first)->previous; \
44 _newp->previous->next = _newp->next->previous = _newp; \
48 /* Remove element from circular, double-linked list. */
49 #define CDBL_LIST_DEL(first, elem) \
51 __typeof (elem) _elem = (elem); \
52 /* Check whether the element is indeed on the list. */ \
53 assert (first != NULL && _elem != NULL \
55 || ({ __typeof (elem) _runp = first->next; \
56 while (_runp != first) \
60 _runp = _runp->next; \
61 _runp == _elem; }))); \
62 if (unlikely (_elem->next == _elem)) \
66 _elem->next->previous = _elem->previous; \
67 _elem->previous->next = _elem->next; \
68 if (unlikely (first == _elem)) \
69 first = _elem->next; \
71 assert ((_elem->next = _elem->previous = NULL, 1)); \
75 /* Add element to the front of a single-linked list. */
76 #define SNGL_LIST_PUSH(first, newp) \
78 __typeof (newp) _newp = (newp); \
79 assert (_newp->next == NULL); \
80 _newp->next = first; \
85 /* Add element to the rear of a circular single-linked list. */
86 #define CSNGL_LIST_ADD_REAR(first, newp) \
88 __typeof (newp) _newp = (newp); \
89 assert (_newp->next == NULL); \
90 if (unlikely ((first) == NULL)) \
91 (first) = _newp->next = _newp; \
94 _newp->next = (first)->next; \
95 (first) = (first)->next = _newp; \