diff options
Diffstat (limited to 'openbsd-compat/sys-queue.h')
-rw-r--r-- | openbsd-compat/sys-queue.h | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h index 5cf0587bd..28aaaa37a 100644 --- a/openbsd-compat/sys-queue.h +++ b/openbsd-compat/sys-queue.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: queue.h,v 1.32 2007/04/30 18:42:34 pedro Exp $ */ | 1 | /* $OpenBSD: queue.h,v 1.36 2012/04/11 13:29:14 naddy Exp $ */ |
2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ | 2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -202,10 +202,10 @@ struct { \ | |||
202 | (var) != SLIST_END(head); \ | 202 | (var) != SLIST_END(head); \ |
203 | (var) = SLIST_NEXT(var, field)) | 203 | (var) = SLIST_NEXT(var, field)) |
204 | 204 | ||
205 | #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ | 205 | #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ |
206 | for ((varp) = &SLIST_FIRST((head)); \ | 206 | for ((var) = SLIST_FIRST(head); \ |
207 | ((var) = *(varp)) != SLIST_END(head); \ | 207 | (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ |
208 | (varp) = &SLIST_NEXT((var), field)) | 208 | (var) = (tvar)) |
209 | 209 | ||
210 | /* | 210 | /* |
211 | * Singly-linked List functions. | 211 | * Singly-linked List functions. |
@@ -224,7 +224,7 @@ struct { \ | |||
224 | (head)->slh_first = (elm); \ | 224 | (head)->slh_first = (elm); \ |
225 | } while (0) | 225 | } while (0) |
226 | 226 | ||
227 | #define SLIST_REMOVE_NEXT(head, elm, field) do { \ | 227 | #define SLIST_REMOVE_AFTER(elm, field) do { \ |
228 | (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ | 228 | (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ |
229 | } while (0) | 229 | } while (0) |
230 | 230 | ||
@@ -276,6 +276,11 @@ struct { \ | |||
276 | (var)!= LIST_END(head); \ | 276 | (var)!= LIST_END(head); \ |
277 | (var) = LIST_NEXT(var, field)) | 277 | (var) = LIST_NEXT(var, field)) |
278 | 278 | ||
279 | #define LIST_FOREACH_SAFE(var, head, field, tvar) \ | ||
280 | for ((var) = LIST_FIRST(head); \ | ||
281 | (var) && ((tvar) = LIST_NEXT(var, field), 1); \ | ||
282 | (var) = (tvar)) | ||
283 | |||
279 | /* | 284 | /* |
280 | * List functions. | 285 | * List functions. |
281 | */ | 286 | */ |
@@ -354,6 +359,11 @@ struct { \ | |||
354 | (var) != SIMPLEQ_END(head); \ | 359 | (var) != SIMPLEQ_END(head); \ |
355 | (var) = SIMPLEQ_NEXT(var, field)) | 360 | (var) = SIMPLEQ_NEXT(var, field)) |
356 | 361 | ||
362 | #define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
363 | for ((var) = SIMPLEQ_FIRST(head); \ | ||
364 | (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ | ||
365 | (var) = (tvar)) | ||
366 | |||
357 | /* | 367 | /* |
358 | * Simple queue functions. | 368 | * Simple queue functions. |
359 | */ | 369 | */ |
@@ -385,6 +395,12 @@ struct { \ | |||
385 | (head)->sqh_last = &(head)->sqh_first; \ | 395 | (head)->sqh_last = &(head)->sqh_first; \ |
386 | } while (0) | 396 | } while (0) |
387 | 397 | ||
398 | #define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ | ||
399 | if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ | ||
400 | == NULL) \ | ||
401 | (head)->sqh_last = &(elm)->field.sqe_next; \ | ||
402 | } while (0) | ||
403 | |||
388 | /* | 404 | /* |
389 | * Tail queue definitions. | 405 | * Tail queue definitions. |
390 | */ | 406 | */ |
@@ -422,11 +438,24 @@ struct { \ | |||
422 | (var) != TAILQ_END(head); \ | 438 | (var) != TAILQ_END(head); \ |
423 | (var) = TAILQ_NEXT(var, field)) | 439 | (var) = TAILQ_NEXT(var, field)) |
424 | 440 | ||
441 | #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
442 | for ((var) = TAILQ_FIRST(head); \ | ||
443 | (var) != TAILQ_END(head) && \ | ||
444 | ((tvar) = TAILQ_NEXT(var, field), 1); \ | ||
445 | (var) = (tvar)) | ||
446 | |||
447 | |||
425 | #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ | 448 | #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ |
426 | for((var) = TAILQ_LAST(head, headname); \ | 449 | for((var) = TAILQ_LAST(head, headname); \ |
427 | (var) != TAILQ_END(head); \ | 450 | (var) != TAILQ_END(head); \ |
428 | (var) = TAILQ_PREV(var, headname, field)) | 451 | (var) = TAILQ_PREV(var, headname, field)) |
429 | 452 | ||
453 | #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ | ||
454 | for ((var) = TAILQ_LAST(head, headname); \ | ||
455 | (var) != TAILQ_END(head) && \ | ||
456 | ((tvar) = TAILQ_PREV(var, headname, field), 1); \ | ||
457 | (var) = (tvar)) | ||
458 | |||
430 | /* | 459 | /* |
431 | * Tail queue functions. | 460 | * Tail queue functions. |
432 | */ | 461 | */ |
@@ -526,11 +555,23 @@ struct { \ | |||
526 | (var) != CIRCLEQ_END(head); \ | 555 | (var) != CIRCLEQ_END(head); \ |
527 | (var) = CIRCLEQ_NEXT(var, field)) | 556 | (var) = CIRCLEQ_NEXT(var, field)) |
528 | 557 | ||
558 | #define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
559 | for ((var) = CIRCLEQ_FIRST(head); \ | ||
560 | (var) != CIRCLEQ_END(head) && \ | ||
561 | ((tvar) = CIRCLEQ_NEXT(var, field), 1); \ | ||
562 | (var) = (tvar)) | ||
563 | |||
529 | #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ | 564 | #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ |
530 | for((var) = CIRCLEQ_LAST(head); \ | 565 | for((var) = CIRCLEQ_LAST(head); \ |
531 | (var) != CIRCLEQ_END(head); \ | 566 | (var) != CIRCLEQ_END(head); \ |
532 | (var) = CIRCLEQ_PREV(var, field)) | 567 | (var) = CIRCLEQ_PREV(var, field)) |
533 | 568 | ||
569 | #define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ | ||
570 | for ((var) = CIRCLEQ_LAST(head, headname); \ | ||
571 | (var) != CIRCLEQ_END(head) && \ | ||
572 | ((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \ | ||
573 | (var) = (tvar)) | ||
574 | |||
534 | /* | 575 | /* |
535 | * Circular queue functions. | 576 | * Circular queue functions. |
536 | */ | 577 | */ |