]> git.sur5r.net Git - openldap/blob - include/ldap_queue.h
memcmp replacement fixes
[openldap] / include / ldap_queue.h
1 /* ldap_queue.h -- queue macros */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Copyright (c) 1991, 1993
17  *      The Regents of the University of California.  All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  * 1. Redistributions of source code must retain the above copyright
23  *    notice, this list of conditions and the following disclaimer.
24  * 2. Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in the
26  *    documentation and/or other materials provided with the distribution.
27  * 3. All advertising materials mentioning features or use of this software
28  *    must display the following acknowledgement:
29  *      This product includes software developed by the University of
30  *      California, Berkeley and its contributors.
31  * 4. Neither the name of the University nor the names of its contributors
32  *    may be used to endorse or promote products derived from this software
33  *    without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  * SUCH DAMAGE.
46  *
47  *      @(#)queue.h     8.5 (Berkeley) 8/20/94
48  * $FreeBSD: src/sys/sys/queue.h,v 1.32.2.5 2001/09/30 21:12:54 luigi Exp $
49  *
50  * See also: ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
51  */
52 /* ACKNOWLEDGEMENTS:
53  * This work is derived from FreeBSD queue.h work.  Adapted for use in
54  * OpenLDAP Software by Kurt D. Zeilenga.
55  */
56
57 #ifndef _LDAP_QUEUE_H_
58 #define _LDAP_QUEUE_H_
59
60 /*
61  * This file defines five types of data structures: singly-linked lists,
62  * singly-linked tail queues, lists, tail queues, and circular queues.
63  *
64  * A singly-linked list is headed by a single forward pointer. The elements
65  * are singly linked for minimum space and pointer manipulation overhead at
66  * the expense of O(n) removal for arbitrary elements. New elements can be
67  * added to the list after an existing element or at the head of the list.
68  * Elements being removed from the head of the list should use the explicit
69  * macro for this purpose for optimum efficiency. A singly-linked list may
70  * only be traversed in the forward direction.  Singly-linked lists are ideal
71  * for applications with large datasets and few or no removals or for
72  * implementing a LIFO queue.
73  *
74  * A singly-linked tail queue is headed by a pair of pointers, one to the
75  * head of the list and the other to the tail of the list. The elements are
76  * singly linked for minimum space and pointer manipulation overhead at the
77  * expense of O(n) removal for arbitrary elements. New elements can be added
78  * to the list after an existing element, at the head of the list, or at the
79  * end of the list. Elements being removed from the head of the tail queue
80  * should use the explicit macro for this purpose for optimum efficiency.
81  * A singly-linked tail queue may only be traversed in the forward direction.
82  * Singly-linked tail queues are ideal for applications with large datasets
83  * and few or no removals or for implementing a FIFO queue.
84  *
85  * A list is headed by a single forward pointer (or an array of forward
86  * pointers for a hash table header). The elements are doubly linked
87  * so that an arbitrary element can be removed without a need to
88  * traverse the list. New elements can be added to the list before
89  * or after an existing element or at the head of the list. A list
90  * may only be traversed in the forward direction.
91  *
92  * A tail queue is headed by a pair of pointers, one to the head of the
93  * list and the other to the tail of the list. The elements are doubly
94  * linked so that an arbitrary element can be removed without a need to
95  * traverse the list. New elements can be added to the list before or
96  * after an existing element, at the head of the list, or at the end of
97  * the list. A tail queue may be traversed in either direction.
98  *
99  * A circle queue is headed by a pair of pointers, one to the head of the
100  * list and the other to the tail of the list. The elements are doubly
101  * linked so that an arbitrary element can be removed without a need to
102  * traverse the list. New elements can be added to the list before or after
103  * an existing element, at the head of the list, or at the end of the list.
104  * A circle queue may be traversed in either direction, but has a more
105  * complex end of list detection.
106  *
107  * For details on the use of these macros, see the queue(3) manual page.
108  * All macros are prefixed with LDAP_.
109  *
110  *                      SLIST_  LIST_   STAILQ_ TAILQ_  CIRCLEQ_
111  * _HEAD                +       +       +       +       +
112  * _ENTRY               +       +       +       +       +
113  * _INIT                +       +       +       +       +
114  * _EMPTY               +       +       +       +       +
115  * _FIRST               +       +       +       +       +
116  * _NEXT                +       +       +       +       +
117  * _PREV                -       -       -       +       +
118  * _LAST                -       -       +       +       +
119  * _FOREACH             +       +       +       +       +
120  * _FOREACH_REVERSE     -       -       -       +       +
121  * _INSERT_HEAD         +       +       +       +       +
122  * _INSERT_BEFORE       -       +       -       +       +
123  * _INSERT_AFTER        +       +       +       +       +
124  * _INSERT_TAIL         -       -       +       +       +
125  * _REMOVE_HEAD         +       -       +       -       -
126  * _REMOVE              +       +       +       +       +
127  *
128  */
129
130 /*
131  * Singly-linked List definitions.
132  */
133 #define LDAP_SLIST_HEAD(name, type)                                     \
134 struct name {                                                           \
135         struct type *slh_first; /* first element */                     \
136 }
137
138 #define LDAP_SLIST_HEAD_INITIALIZER(head)                               \
139         { NULL }
140
141 #define LDAP_SLIST_ENTRY(type)                                          \
142 struct {                                                                \
143         struct type *sle_next;  /* next element */                      \
144 }
145
146 #define LDAP_SLIST_ENTRY_INITIALIZER(entry)                             \
147         { NULL }
148
149 /*
150  * Singly-linked List functions.
151  */
152 #define LDAP_SLIST_EMPTY(head)  ((head)->slh_first == NULL)
153
154 #define LDAP_SLIST_FIRST(head)  ((head)->slh_first)
155
156 #define LDAP_SLIST_FOREACH(var, head, field)                            \
157         for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
158
159 #define LDAP_SLIST_INIT(head) {                                         \
160         (head)->slh_first = NULL;                                       \
161 }
162
163 #define LDAP_SLIST_INSERT_AFTER(slistelm, elm, field) do {              \
164         (elm)->field.sle_next = (slistelm)->field.sle_next;             \
165         (slistelm)->field.sle_next = (elm);                             \
166 } while (0)
167
168 #define LDAP_SLIST_INSERT_HEAD(head, elm, field) do {                   \
169         (elm)->field.sle_next = (head)->slh_first;                      \
170         (head)->slh_first = (elm);                                      \
171 } while (0)
172
173 #define LDAP_SLIST_NEXT(elm, field)     ((elm)->field.sle_next)
174
175 #define LDAP_SLIST_REMOVE_HEAD(head, field) do {                        \
176         (head)->slh_first = (head)->slh_first->field.sle_next;          \
177 } while (0)
178
179 #define LDAP_SLIST_REMOVE(head, elm, type, field) do {                  \
180         if ((head)->slh_first == (elm)) {                               \
181                 LDAP_SLIST_REMOVE_HEAD((head), field);                  \
182         }                                                               \
183         else {                                                          \
184                 struct type *curelm = (head)->slh_first;                \
185                 while( curelm->field.sle_next != (elm) )                \
186                         curelm = curelm->field.sle_next;                \
187                 curelm->field.sle_next =                                \
188                     curelm->field.sle_next->field.sle_next;             \
189         }                                                               \
190 } while (0)
191
192 /*
193  * Singly-linked Tail queue definitions.
194  */
195 #define LDAP_STAILQ_HEAD(name, type)                                    \
196 struct name {                                                           \
197         struct type *stqh_first;/* first element */                     \
198         struct type **stqh_last;/* addr of last next element */         \
199 }
200
201 #define LDAP_STAILQ_HEAD_INITIALIZER(head)                              \
202         { NULL, &(head).stqh_first }
203
204 #define LDAP_STAILQ_ENTRY(type)                                         \
205 struct {                                                                \
206         struct type *stqe_next; /* next element */                      \
207 }
208
209 #define LDAP_STAILQ_ENTRY_INITIALIZER(entry)                            \
210         { NULL }
211
212 /*
213  * Singly-linked Tail queue functions.
214  */
215 #define LDAP_STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
216
217 #define LDAP_STAILQ_INIT(head) do {                                     \
218         (head)->stqh_first = NULL;                                      \
219         (head)->stqh_last = &(head)->stqh_first;                        \
220 } while (0)
221
222 #define LDAP_STAILQ_FIRST(head) ((head)->stqh_first)
223
224 #define LDAP_STAILQ_LAST(head, type, field)                             \
225         (LDAP_STAILQ_EMPTY(head) ?                                      \
226                 NULL :                                                  \
227                 ((struct type *)                                        \
228                 ((char *)((head)->stqh_last) - offsetof(struct type, field))))
229
230 #define LDAP_STAILQ_FOREACH(var, head, field)                           \
231         for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next)
232
233 #define LDAP_STAILQ_INSERT_HEAD(head, elm, field) do {                  \
234         if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)      \
235                 (head)->stqh_last = &(elm)->field.stqe_next;            \
236         (head)->stqh_first = (elm);                                     \
237 } while (0)
238
239 #define LDAP_STAILQ_INSERT_TAIL(head, elm, field) do {                  \
240         (elm)->field.stqe_next = NULL;                                  \
241         *(head)->stqh_last = (elm);                                     \
242         (head)->stqh_last = &(elm)->field.stqe_next;                    \
243 } while (0)
244
245 #define LDAP_STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {          \
246         if (((elm)->field.stqe_next = (tqelm)->field.stqe_next) == NULL)\
247                 (head)->stqh_last = &(elm)->field.stqe_next;            \
248         (tqelm)->field.stqe_next = (elm);                               \
249 } while (0)
250
251 #define LDAP_STAILQ_NEXT(elm, field)    ((elm)->field.stqe_next)
252
253 #define LDAP_STAILQ_REMOVE_HEAD(head, field) do {                       \
254         if (((head)->stqh_first =                                       \
255              (head)->stqh_first->field.stqe_next) == NULL)              \
256                 (head)->stqh_last = &(head)->stqh_first;                \
257 } while (0)
258
259 #define LDAP_STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do {            \
260         if (((head)->stqh_first = (elm)->field.stqe_next) == NULL)      \
261                 (head)->stqh_last = &(head)->stqh_first;                \
262 } while (0)
263
264 #define LDAP_STAILQ_REMOVE(head, elm, type, field) do {                 \
265         if ((head)->stqh_first == (elm)) {                              \
266                 LDAP_STAILQ_REMOVE_HEAD(head, field);                   \
267         }                                                               \
268         else {                                                          \
269                 struct type *curelm = (head)->stqh_first;               \
270                 while( curelm->field.stqe_next != (elm) )               \
271                         curelm = curelm->field.stqe_next;               \
272                 if((curelm->field.stqe_next =                           \
273                     curelm->field.stqe_next->field.stqe_next) == NULL)  \
274                         (head)->stqh_last = &(curelm)->field.stqe_next; \
275         }                                                               \
276 } while (0)
277
278 /*
279  * List definitions.
280  */
281 #define LDAP_LIST_HEAD(name, type)                                      \
282 struct name {                                                           \
283         struct type *lh_first;  /* first element */                     \
284 }
285
286 #define LDAP_LIST_HEAD_INITIALIZER(head)                                \
287         { NULL }
288
289 #define LDAP_LIST_ENTRY(type)                                           \
290 struct {                                                                \
291         struct type *le_next;   /* next element */                      \
292         struct type **le_prev;  /* address of previous next element */  \
293 }
294
295 #define LDAP_LIST_ENTRY_INITIALIZER(entry)                      \
296         { NULL, NULL }
297
298 /*
299  * List functions.
300  */
301
302 #define LDAP_LIST_EMPTY(head) ((head)->lh_first == NULL)
303
304 #define LDAP_LIST_FIRST(head)   ((head)->lh_first)
305
306 #define LDAP_LIST_FOREACH(var, head, field)                             \
307         for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next)
308
309 #define LDAP_LIST_INIT(head) do {                                       \
310         (head)->lh_first = NULL;                                        \
311 } while (0)
312
313 #define LDAP_LIST_INSERT_AFTER(listelm, elm, field) do {                \
314         if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
315                 (listelm)->field.le_next->field.le_prev =               \
316                     &(elm)->field.le_next;                              \
317         (listelm)->field.le_next = (elm);                               \
318         (elm)->field.le_prev = &(listelm)->field.le_next;               \
319 } while (0)
320
321 #define LDAP_LIST_INSERT_BEFORE(listelm, elm, field) do {               \
322         (elm)->field.le_prev = (listelm)->field.le_prev;                \
323         (elm)->field.le_next = (listelm);                               \
324         *(listelm)->field.le_prev = (elm);                              \
325         (listelm)->field.le_prev = &(elm)->field.le_next;               \
326 } while (0)
327
328 #define LDAP_LIST_INSERT_HEAD(head, elm, field) do {                    \
329         if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
330                 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
331         (head)->lh_first = (elm);                                       \
332         (elm)->field.le_prev = &(head)->lh_first;                       \
333 } while (0)
334
335 #define LDAP_LIST_NEXT(elm, field)      ((elm)->field.le_next)
336
337 #define LDAP_LIST_REMOVE(elm, field) do {                               \
338         if ((elm)->field.le_next != NULL)                               \
339                 (elm)->field.le_next->field.le_prev =                   \
340                     (elm)->field.le_prev;                               \
341         *(elm)->field.le_prev = (elm)->field.le_next;                   \
342 } while (0)
343
344 /*
345  * Tail queue definitions.
346  */
347 #define LDAP_TAILQ_HEAD(name, type)                                     \
348 struct name {                                                           \
349         struct type *tqh_first; /* first element */                     \
350         struct type **tqh_last; /* addr of last next element */         \
351 }
352
353 #define LDAP_TAILQ_HEAD_INITIALIZER(head)                               \
354         { NULL, &(head).tqh_first }
355
356 #define LDAP_TAILQ_ENTRY(type)                                          \
357 struct {                                                                \
358         struct type *tqe_next;  /* next element */                      \
359         struct type **tqe_prev; /* address of previous next element */  \
360 }
361
362 #define LDAP_TAILQ_ENTRY_INITIALIZER(entry)                             \
363         { NULL, NULL }
364
365 /*
366  * Tail queue functions.
367  */
368 #define LDAP_TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
369
370 #define LDAP_TAILQ_FOREACH(var, head, field)                            \
371         for (var = LDAP_TAILQ_FIRST(head); var; var = LDAP_TAILQ_NEXT(var, field))
372
373 #define LDAP_TAILQ_FOREACH_REVERSE(var, head, type, field)              \
374         for ((var) = LDAP_TAILQ_LAST((head), type, field);              \
375              (var);                                                     \
376              (var) = LDAP_TAILQ_PREV((var), head, type, field))
377
378 #define LDAP_TAILQ_FIRST(head) ((head)->tqh_first)
379
380 #define LDAP_TAILQ_LAST(head, type, field)                              \
381         (LDAP_TAILQ_EMPTY(head) ?                                       \
382                 NULL :                                                  \
383                 ((struct type *)                                        \
384                 ((char *)((head)->tqh_last) - offsetof(struct type, field))))
385
386 #define LDAP_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
387
388 #define LDAP_TAILQ_PREV(elm, head, type, field)                         \
389         ((struct type *)((elm)->field.tqe_prev) == LDAP_TAILQ_FIRST(head) ? \
390         NULL :                                                          \
391         ((struct type *)                                                \
392         ((char *)((elm)->field.tqe_prev) - offsetof(struct type, field))))
393
394 #define LDAP_TAILQ_INIT(head) do {                                      \
395         (head)->tqh_first = NULL;                                       \
396         (head)->tqh_last = &(head)->tqh_first;                          \
397 } while (0)
398
399 #define LDAP_TAILQ_INSERT_HEAD(head, elm, field) do {                   \
400         if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)        \
401                 (head)->tqh_first->field.tqe_prev =                     \
402                     &(elm)->field.tqe_next;                             \
403         else                                                            \
404                 (head)->tqh_last = &(elm)->field.tqe_next;              \
405         (head)->tqh_first = (elm);                                      \
406         (elm)->field.tqe_prev = &(head)->tqh_first;                     \
407 } while (0)
408
409 #define LDAP_TAILQ_INSERT_TAIL(head, elm, field) do {                   \
410         (elm)->field.tqe_next = NULL;                                   \
411         (elm)->field.tqe_prev = (head)->tqh_last;                       \
412         *(head)->tqh_last = (elm);                                      \
413         (head)->tqh_last = &(elm)->field.tqe_next;                      \
414 } while (0)
415
416 #define LDAP_TAILQ_INSERT_AFTER(head, listelm, elm, field) do {         \
417         if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
418                 (elm)->field.tqe_next->field.tqe_prev =                 \
419                     &(elm)->field.tqe_next;                             \
420         else                                                            \
421                 (head)->tqh_last = &(elm)->field.tqe_next;              \
422         (listelm)->field.tqe_next = (elm);                              \
423         (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
424 } while (0)
425
426 #define LDAP_TAILQ_INSERT_BEFORE(listelm, elm, field) do {              \
427         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
428         (elm)->field.tqe_next = (listelm);                              \
429         *(listelm)->field.tqe_prev = (elm);                             \
430         (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
431 } while (0)
432
433 #define LDAP_TAILQ_REMOVE(head, elm, field) do {                        \
434         if (((elm)->field.tqe_next) != NULL)                            \
435                 (elm)->field.tqe_next->field.tqe_prev =                 \
436                     (elm)->field.tqe_prev;                              \
437         else                                                            \
438                 (head)->tqh_last = (elm)->field.tqe_prev;               \
439         *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
440 } while (0)
441
442 /*
443  * Circular queue definitions.
444  */
445 #define LDAP_CIRCLEQ_HEAD(name, type)                                   \
446 struct name {                                                           \
447         struct type *cqh_first;         /* first element */             \
448         struct type *cqh_last;          /* last element */              \
449 }
450
451 #define LDAP_CIRCLEQ_ENTRY(type)                                        \
452 struct {                                                                \
453         struct type *cqe_next;          /* next element */              \
454         struct type *cqe_prev;          /* previous element */          \
455 }
456
457 /*
458  * Circular queue functions.
459  */
460 #define LDAP_CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
461
462 #define LDAP_CIRCLEQ_FIRST(head) ((head)->cqh_first)
463
464 #define LDAP_CIRCLEQ_FOREACH(var, head, field)                          \
465         for((var) = (head)->cqh_first;                                  \
466             (var) != (void *)(head);                                    \
467             (var) = (var)->field.cqe_next)
468
469 #define LDAP_CIRCLEQ_FOREACH_REVERSE(var, head, field)                  \
470         for((var) = (head)->cqh_last;                                   \
471             (var) != (void *)(head);                                    \
472             (var) = (var)->field.cqe_prev)
473
474 #define LDAP_CIRCLEQ_INIT(head) do {                                    \
475         (head)->cqh_first = (void *)(head);                             \
476         (head)->cqh_last = (void *)(head);                              \
477 } while (0)
478
479 #define LDAP_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {       \
480         (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
481         (elm)->field.cqe_prev = (listelm);                              \
482         if ((listelm)->field.cqe_next == (void *)(head))                \
483                 (head)->cqh_last = (elm);                               \
484         else                                                            \
485                 (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
486         (listelm)->field.cqe_next = (elm);                              \
487 } while (0)
488
489 #define LDAP_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {      \
490         (elm)->field.cqe_next = (listelm);                              \
491         (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
492         if ((listelm)->field.cqe_prev == (void *)(head))                \
493                 (head)->cqh_first = (elm);                              \
494         else                                                            \
495                 (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
496         (listelm)->field.cqe_prev = (elm);                              \
497 } while (0)
498
499 #define LDAP_CIRCLEQ_INSERT_HEAD(head, elm, field) do {                 \
500         (elm)->field.cqe_next = (head)->cqh_first;                      \
501         (elm)->field.cqe_prev = (void *)(head);                         \
502         if ((head)->cqh_last == (void *)(head))                         \
503                 (head)->cqh_last = (elm);                               \
504         else                                                            \
505                 (head)->cqh_first->field.cqe_prev = (elm);              \
506         (head)->cqh_first = (elm);                                      \
507 } while (0)
508
509 #define LDAP_CIRCLEQ_INSERT_TAIL(head, elm, field) do {                 \
510         (elm)->field.cqe_next = (void *)(head);                         \
511         (elm)->field.cqe_prev = (head)->cqh_last;                       \
512         if ((head)->cqh_first == (void *)(head))                        \
513                 (head)->cqh_first = (elm);                              \
514         else                                                            \
515                 (head)->cqh_last->field.cqe_next = (elm);               \
516         (head)->cqh_last = (elm);                                       \
517 } while (0)
518
519 #define LDAP_CIRCLEQ_LAST(head) ((head)->cqh_last)
520
521 #define LDAP_CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
522
523 #define LDAP_CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
524
525 #define LDAP_CIRCLEQ_REMOVE(head, elm, field) do {                      \
526         if ((elm)->field.cqe_next == (void *)(head))                    \
527                 (head)->cqh_last = (elm)->field.cqe_prev;               \
528         else                                                            \
529                 (elm)->field.cqe_next->field.cqe_prev =                 \
530                     (elm)->field.cqe_prev;                              \
531         if ((elm)->field.cqe_prev == (void *)(head))                    \
532                 (head)->cqh_first = (elm)->field.cqe_next;              \
533         else                                                            \
534                 (elm)->field.cqe_prev->field.cqe_next =                 \
535                     (elm)->field.cqe_next;                              \
536 } while (0)
537
538 #endif /* !_LDAP_QUEUE_H_ */