4 #error "Do not use C++: this is a C application."
6 #if !defined(__GNUC__) || (__GNUC__ < 4)
7 #define __attribute__(x)
9 #if defined(__linux__) || defined(__MINT__)
12 #if !defined(__BEGIN_DECLS)
13 # define __BEGIN_DECLS
15 #if !defined(__END_DECLS)
18 #include <sys/types.h>
20 #define HAVE_ARC4RANDOM 1
21 #define HAVE_B64_NTOP 1
22 #define HAVE_CAPSICUM 0
23 #define HAVE_ENDIAN_H 0
25 #define HAVE_EXPLICIT_BZERO 0
26 #define HAVE_GETPROGNAME 1
30 #define HAVE_MEMRCHR 0
31 #define HAVE_MEMSET_S 1
32 #define HAVE_PATH_MAX 1
34 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME 0
35 #define HAVE_READPASSPHRASE 1
36 #define HAVE_REALLOCARRAY 0
37 #define HAVE_RECALLOCARRAY 0
38 #define HAVE_SANDBOX_INIT 1
39 #define HAVE_SECCOMP_FILTER 0
40 #define HAVE_SOCK_NONBLOCK 0
41 #define HAVE_STRLCAT 1
42 #define HAVE_STRLCPY 1
43 #define HAVE_STRNDUP 1
44 #define HAVE_STRNLEN 1
45 #define HAVE_STRTONUM 0
46 #define HAVE_SYS_QUEUE 1
47 #define HAVE_SYS_TREE 0
48 #define HAVE_SYSTRACE 0
51 #define HAVE___PROGNAME 1
52 #define MD5_BLOCK_LENGTH 64
53 #define MD5_DIGEST_LENGTH 16
54 #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
58 u_int8_t buffer[MD5_BLOCK_LENGTH];
61 extern void MD5Update(
MD5_CTX *,
const u_int8_t *,
size_t);
63 extern void MD5Transform(u_int32_t [4],
const u_int8_t [MD5_BLOCK_LENGTH]);
64 extern char *MD5End(
MD5_CTX *,
char *);
65 extern void MD5Final(u_int8_t [MD5_DIGEST_LENGTH],
MD5_CTX *);
66 extern void explicit_bzero(
void *,
size_t);
67 void *memrchr(
const void *b,
int,
size_t);
68 extern void *reallocarray(
void *,
size_t,
size_t);
69 extern void *recallocarray(
void *,
size_t,
size_t,
size_t);
70 extern long long strtonum(
const char *,
long long,
long long,
const char **);
126 #define SPLAY_HEAD(name, type) \
128 struct type *sph_root; \
131 #define SPLAY_INITIALIZER(root) \
134 #define SPLAY_INIT(root) do { \
135 (root)->sph_root = NULL; \
138 #define SPLAY_ENTRY(type) \
140 struct type *spe_left; \
141 struct type *spe_right; \
144 #define SPLAY_LEFT(elm, field) (elm)->field.spe_left
145 #define SPLAY_RIGHT(elm, field) (elm)->field.spe_right
146 #define SPLAY_ROOT(head) (head)->sph_root
147 #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL)
150 #define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \
151 SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \
152 SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
153 (head)->sph_root = tmp; \
156 #define SPLAY_ROTATE_LEFT(head, tmp, field) do { \
157 SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \
158 SPLAY_LEFT(tmp, field) = (head)->sph_root; \
159 (head)->sph_root = tmp; \
162 #define SPLAY_LINKLEFT(head, tmp, field) do { \
163 SPLAY_LEFT(tmp, field) = (head)->sph_root; \
164 tmp = (head)->sph_root; \
165 (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \
168 #define SPLAY_LINKRIGHT(head, tmp, field) do { \
169 SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
170 tmp = (head)->sph_root; \
171 (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \
174 #define SPLAY_ASSEMBLE(head, node, left, right, field) do { \
175 SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \
176 SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\
177 SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \
178 SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \
183 #define SPLAY_PROTOTYPE(name, type, field, cmp) \
184 void name##_SPLAY(struct name *, struct type *); \
185 void name##_SPLAY_MINMAX(struct name *, int); \
186 struct type *name##_SPLAY_INSERT(struct name *, struct type *); \
187 struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \
190 static __inline struct type * \
191 name##_SPLAY_FIND(struct name *head, struct type *elm) \
193 if (SPLAY_EMPTY(head)) \
195 name##_SPLAY(head, elm); \
196 if ((cmp)(elm, (head)->sph_root) == 0) \
197 return (head->sph_root); \
201 static __inline struct type * \
202 name##_SPLAY_NEXT(struct name *head, struct type *elm) \
204 name##_SPLAY(head, elm); \
205 if (SPLAY_RIGHT(elm, field) != NULL) { \
206 elm = SPLAY_RIGHT(elm, field); \
207 while (SPLAY_LEFT(elm, field) != NULL) { \
208 elm = SPLAY_LEFT(elm, field); \
215 static __inline struct type * \
216 name##_SPLAY_MIN_MAX(struct name *head, int val) \
218 name##_SPLAY_MINMAX(head, val); \
219 return (SPLAY_ROOT(head)); \
225 #define SPLAY_GENERATE(name, type, field, cmp) \
227 name##_SPLAY_INSERT(struct name *head, struct type *elm) \
229 if (SPLAY_EMPTY(head)) { \
230 SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \
233 name##_SPLAY(head, elm); \
234 __comp = (cmp)(elm, (head)->sph_root); \
236 SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\
237 SPLAY_RIGHT(elm, field) = (head)->sph_root; \
238 SPLAY_LEFT((head)->sph_root, field) = NULL; \
239 } else if (__comp > 0) { \
240 SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\
241 SPLAY_LEFT(elm, field) = (head)->sph_root; \
242 SPLAY_RIGHT((head)->sph_root, field) = NULL; \
244 return ((head)->sph_root); \
246 (head)->sph_root = (elm); \
251 name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
253 struct type *__tmp; \
254 if (SPLAY_EMPTY(head)) \
256 name##_SPLAY(head, elm); \
257 if ((cmp)(elm, (head)->sph_root) == 0) { \
258 if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \
259 (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\
261 __tmp = SPLAY_RIGHT((head)->sph_root, field); \
262 (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\
263 name##_SPLAY(head, elm); \
264 SPLAY_RIGHT((head)->sph_root, field) = __tmp; \
272 name##_SPLAY(struct name *head, struct type *elm) \
274 struct type __node, *__left, *__right, *__tmp; \
277 SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
278 __left = __right = &__node; \
280 while ((__comp = (cmp)(elm, (head)->sph_root))) { \
282 __tmp = SPLAY_LEFT((head)->sph_root, field); \
285 if ((cmp)(elm, __tmp) < 0){ \
286 SPLAY_ROTATE_RIGHT(head, __tmp, field); \
287 if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
290 SPLAY_LINKLEFT(head, __right, field); \
291 } else if (__comp > 0) { \
292 __tmp = SPLAY_RIGHT((head)->sph_root, field); \
295 if ((cmp)(elm, __tmp) > 0){ \
296 SPLAY_ROTATE_LEFT(head, __tmp, field); \
297 if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
300 SPLAY_LINKRIGHT(head, __left, field); \
303 SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
309 void name##_SPLAY_MINMAX(struct name *head, int __comp) \
311 struct type __node, *__left, *__right, *__tmp; \
313 SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
314 __left = __right = &__node; \
318 __tmp = SPLAY_LEFT((head)->sph_root, field); \
322 SPLAY_ROTATE_RIGHT(head, __tmp, field); \
323 if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
326 SPLAY_LINKLEFT(head, __right, field); \
327 } else if (__comp > 0) { \
328 __tmp = SPLAY_RIGHT((head)->sph_root, field); \
332 SPLAY_ROTATE_LEFT(head, __tmp, field); \
333 if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
336 SPLAY_LINKRIGHT(head, __left, field); \
339 SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
342 #define SPLAY_NEGINF -1
345 #define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y)
346 #define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y)
347 #define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y)
348 #define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y)
349 #define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \
350 : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
351 #define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \
352 : name##_SPLAY_MIN_MAX(x, SPLAY_INF))
354 #define SPLAY_FOREACH(x, name, head) \
355 for ((x) = SPLAY_MIN(name, head); \
357 (x) = SPLAY_NEXT(name, head, x))
360 #define RB_HEAD(name, type) \
362 struct type *rbh_root; \
365 #define RB_INITIALIZER(root) \
368 #define RB_INIT(root) do { \
369 (root)->rbh_root = NULL; \
374 #define RB_ENTRY(type) \
376 struct type *rbe_left; \
377 struct type *rbe_right; \
378 struct type *rbe_parent; \
382 #define RB_LEFT(elm, field) (elm)->field.rbe_left
383 #define RB_RIGHT(elm, field) (elm)->field.rbe_right
384 #define RB_PARENT(elm, field) (elm)->field.rbe_parent
385 #define RB_COLOR(elm, field) (elm)->field.rbe_color
386 #define RB_ROOT(head) (head)->rbh_root
387 #define RB_EMPTY(head) (RB_ROOT(head) == NULL)
389 #define RB_SET(elm, parent, field) do { \
390 RB_PARENT(elm, field) = parent; \
391 RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
392 RB_COLOR(elm, field) = RB_RED; \
395 #define RB_SET_BLACKRED(black, red, field) do { \
396 RB_COLOR(black, field) = RB_BLACK; \
397 RB_COLOR(red, field) = RB_RED; \
401 #define RB_AUGMENT(x) do {} while (0)
404 #define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
405 (tmp) = RB_RIGHT(elm, field); \
406 if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \
407 RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \
410 if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \
411 if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
412 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
414 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
416 (head)->rbh_root = (tmp); \
417 RB_LEFT(tmp, field) = (elm); \
418 RB_PARENT(elm, field) = (tmp); \
420 if ((RB_PARENT(tmp, field))) \
421 RB_AUGMENT(RB_PARENT(tmp, field)); \
424 #define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
425 (tmp) = RB_LEFT(elm, field); \
426 if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \
427 RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \
430 if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \
431 if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
432 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
434 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
436 (head)->rbh_root = (tmp); \
437 RB_RIGHT(tmp, field) = (elm); \
438 RB_PARENT(elm, field) = (tmp); \
440 if ((RB_PARENT(tmp, field))) \
441 RB_AUGMENT(RB_PARENT(tmp, field)); \
445 #define RB_PROTOTYPE(name, type, field, cmp) \
446 RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
447 #define RB_PROTOTYPE_STATIC(name, type, field, cmp) \
448 RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
449 #define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \
450 attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \
451 attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\
452 attr struct type *name##_RB_REMOVE(struct name *, struct type *); \
453 attr struct type *name##_RB_INSERT(struct name *, struct type *); \
454 attr struct type *name##_RB_FIND(struct name *, struct type *); \
455 attr struct type *name##_RB_NFIND(struct name *, struct type *); \
456 attr struct type *name##_RB_NEXT(struct type *); \
457 attr struct type *name##_RB_PREV(struct type *); \
458 attr struct type *name##_RB_MINMAX(struct name *, int); \
464 #define RB_GENERATE(name, type, field, cmp) \
465 RB_GENERATE_INTERNAL(name, type, field, cmp,)
466 #define RB_GENERATE_STATIC(name, type, field, cmp) \
467 RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
468 #define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \
470 name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \
472 struct type *parent, *gparent, *tmp; \
473 while ((parent = RB_PARENT(elm, field)) && \
474 RB_COLOR(parent, field) == RB_RED) { \
475 gparent = RB_PARENT(parent, field); \
476 if (parent == RB_LEFT(gparent, field)) { \
477 tmp = RB_RIGHT(gparent, field); \
478 if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
479 RB_COLOR(tmp, field) = RB_BLACK; \
480 RB_SET_BLACKRED(parent, gparent, field);\
484 if (RB_RIGHT(parent, field) == elm) { \
485 RB_ROTATE_LEFT(head, parent, tmp, field);\
490 RB_SET_BLACKRED(parent, gparent, field); \
491 RB_ROTATE_RIGHT(head, gparent, tmp, field); \
493 tmp = RB_LEFT(gparent, field); \
494 if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
495 RB_COLOR(tmp, field) = RB_BLACK; \
496 RB_SET_BLACKRED(parent, gparent, field);\
500 if (RB_LEFT(parent, field) == elm) { \
501 RB_ROTATE_RIGHT(head, parent, tmp, field);\
506 RB_SET_BLACKRED(parent, gparent, field); \
507 RB_ROTATE_LEFT(head, gparent, tmp, field); \
510 RB_COLOR(head->rbh_root, field) = RB_BLACK; \
514 name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \
517 while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \
518 elm != RB_ROOT(head)) { \
519 if (RB_LEFT(parent, field) == elm) { \
520 tmp = RB_RIGHT(parent, field); \
521 if (RB_COLOR(tmp, field) == RB_RED) { \
522 RB_SET_BLACKRED(tmp, parent, field); \
523 RB_ROTATE_LEFT(head, parent, tmp, field);\
524 tmp = RB_RIGHT(parent, field); \
526 if ((RB_LEFT(tmp, field) == NULL || \
527 RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
528 (RB_RIGHT(tmp, field) == NULL || \
529 RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
530 RB_COLOR(tmp, field) = RB_RED; \
532 parent = RB_PARENT(elm, field); \
534 if (RB_RIGHT(tmp, field) == NULL || \
535 RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\
536 struct type *oleft; \
537 if ((oleft = RB_LEFT(tmp, field)))\
538 RB_COLOR(oleft, field) = RB_BLACK;\
539 RB_COLOR(tmp, field) = RB_RED; \
540 RB_ROTATE_RIGHT(head, tmp, oleft, field);\
541 tmp = RB_RIGHT(parent, field); \
543 RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
544 RB_COLOR(parent, field) = RB_BLACK; \
545 if (RB_RIGHT(tmp, field)) \
546 RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\
547 RB_ROTATE_LEFT(head, parent, tmp, field);\
548 elm = RB_ROOT(head); \
552 tmp = RB_LEFT(parent, field); \
553 if (RB_COLOR(tmp, field) == RB_RED) { \
554 RB_SET_BLACKRED(tmp, parent, field); \
555 RB_ROTATE_RIGHT(head, parent, tmp, field);\
556 tmp = RB_LEFT(parent, field); \
558 if ((RB_LEFT(tmp, field) == NULL || \
559 RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
560 (RB_RIGHT(tmp, field) == NULL || \
561 RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
562 RB_COLOR(tmp, field) = RB_RED; \
564 parent = RB_PARENT(elm, field); \
566 if (RB_LEFT(tmp, field) == NULL || \
567 RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\
568 struct type *oright; \
569 if ((oright = RB_RIGHT(tmp, field)))\
570 RB_COLOR(oright, field) = RB_BLACK;\
571 RB_COLOR(tmp, field) = RB_RED; \
572 RB_ROTATE_LEFT(head, tmp, oright, field);\
573 tmp = RB_LEFT(parent, field); \
575 RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
576 RB_COLOR(parent, field) = RB_BLACK; \
577 if (RB_LEFT(tmp, field)) \
578 RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\
579 RB_ROTATE_RIGHT(head, parent, tmp, field);\
580 elm = RB_ROOT(head); \
586 RB_COLOR(elm, field) = RB_BLACK; \
590 name##_RB_REMOVE(struct name *head, struct type *elm) \
592 struct type *child, *parent, *old = elm; \
594 if (RB_LEFT(elm, field) == NULL) \
595 child = RB_RIGHT(elm, field); \
596 else if (RB_RIGHT(elm, field) == NULL) \
597 child = RB_LEFT(elm, field); \
600 elm = RB_RIGHT(elm, field); \
601 while ((left = RB_LEFT(elm, field))) \
603 child = RB_RIGHT(elm, field); \
604 parent = RB_PARENT(elm, field); \
605 color = RB_COLOR(elm, field); \
607 RB_PARENT(child, field) = parent; \
609 if (RB_LEFT(parent, field) == elm) \
610 RB_LEFT(parent, field) = child; \
612 RB_RIGHT(parent, field) = child; \
613 RB_AUGMENT(parent); \
615 RB_ROOT(head) = child; \
616 if (RB_PARENT(elm, field) == old) \
618 (elm)->field = (old)->field; \
619 if (RB_PARENT(old, field)) { \
620 if (RB_LEFT(RB_PARENT(old, field), field) == old)\
621 RB_LEFT(RB_PARENT(old, field), field) = elm;\
623 RB_RIGHT(RB_PARENT(old, field), field) = elm;\
624 RB_AUGMENT(RB_PARENT(old, field)); \
626 RB_ROOT(head) = elm; \
627 RB_PARENT(RB_LEFT(old, field), field) = elm; \
628 if (RB_RIGHT(old, field)) \
629 RB_PARENT(RB_RIGHT(old, field), field) = elm; \
634 } while ((left = RB_PARENT(left, field))); \
638 parent = RB_PARENT(elm, field); \
639 color = RB_COLOR(elm, field); \
641 RB_PARENT(child, field) = parent; \
643 if (RB_LEFT(parent, field) == elm) \
644 RB_LEFT(parent, field) = child; \
646 RB_RIGHT(parent, field) = child; \
647 RB_AUGMENT(parent); \
649 RB_ROOT(head) = child; \
651 if (color == RB_BLACK) \
652 name##_RB_REMOVE_COLOR(head, parent, child); \
658 name##_RB_INSERT(struct name *head, struct type *elm) \
661 struct type *parent = NULL; \
663 tmp = RB_ROOT(head); \
666 comp = (cmp)(elm, parent); \
668 tmp = RB_LEFT(tmp, field); \
670 tmp = RB_RIGHT(tmp, field); \
674 RB_SET(elm, parent, field); \
675 if (parent != NULL) { \
677 RB_LEFT(parent, field) = elm; \
679 RB_RIGHT(parent, field) = elm; \
680 RB_AUGMENT(parent); \
682 RB_ROOT(head) = elm; \
683 name##_RB_INSERT_COLOR(head, elm); \
689 name##_RB_FIND(struct name *head, struct type *elm) \
691 struct type *tmp = RB_ROOT(head); \
694 comp = cmp(elm, tmp); \
696 tmp = RB_LEFT(tmp, field); \
698 tmp = RB_RIGHT(tmp, field); \
707 name##_RB_NFIND(struct name *head, struct type *elm) \
709 struct type *tmp = RB_ROOT(head); \
710 struct type *res = NULL; \
713 comp = cmp(elm, tmp); \
716 tmp = RB_LEFT(tmp, field); \
719 tmp = RB_RIGHT(tmp, field); \
728 name##_RB_NEXT(struct type *elm) \
730 if (RB_RIGHT(elm, field)) { \
731 elm = RB_RIGHT(elm, field); \
732 while (RB_LEFT(elm, field)) \
733 elm = RB_LEFT(elm, field); \
735 if (RB_PARENT(elm, field) && \
736 (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
737 elm = RB_PARENT(elm, field); \
739 while (RB_PARENT(elm, field) && \
740 (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
741 elm = RB_PARENT(elm, field); \
742 elm = RB_PARENT(elm, field); \
750 name##_RB_PREV(struct type *elm) \
752 if (RB_LEFT(elm, field)) { \
753 elm = RB_LEFT(elm, field); \
754 while (RB_RIGHT(elm, field)) \
755 elm = RB_RIGHT(elm, field); \
757 if (RB_PARENT(elm, field) && \
758 (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \
759 elm = RB_PARENT(elm, field); \
761 while (RB_PARENT(elm, field) && \
762 (elm == RB_LEFT(RB_PARENT(elm, field), field)))\
763 elm = RB_PARENT(elm, field); \
764 elm = RB_PARENT(elm, field); \
771 name##_RB_MINMAX(struct name *head, int val) \
773 struct type *tmp = RB_ROOT(head); \
774 struct type *parent = NULL; \
778 tmp = RB_LEFT(tmp, field); \
780 tmp = RB_RIGHT(tmp, field); \
788 #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y)
789 #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y)
790 #define RB_FIND(name, x, y) name##_RB_FIND(x, y)
791 #define RB_NFIND(name, x, y) name##_RB_NFIND(x, y)
792 #define RB_NEXT(name, x, y) name##_RB_NEXT(y)
793 #define RB_PREV(name, x, y) name##_RB_PREV(y)
794 #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF)
795 #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF)
797 #define RB_FOREACH(x, name, head) \
798 for ((x) = RB_MIN(name, head); \
800 (x) = name##_RB_NEXT(x))
802 #define RB_FOREACH_SAFE(x, name, head, y) \
803 for ((x) = RB_MIN(name, head); \
804 ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \
807 #define RB_FOREACH_REVERSE(x, name, head) \
808 for ((x) = RB_MAX(name, head); \
810 (x) = name##_RB_PREV(x))
812 #define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \
813 for ((x) = RB_MAX(name, head); \
814 ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \