X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Flist.h;h=e55b91cea4ad9c0184ee07390ba78a11c9c81a0a;hp=9a491b990efe0f024d703c23f7eb9887ceee20c9;hb=9f5650aecb22a1d864b2c0b749910556795f1490;hpb=5430f7f2bc7330f3088b894166bf3524a067e3d8 diff --git a/src/shared/list.h b/src/shared/list.h index 9a491b990..e55b91cea 100644 --- a/src/shared/list.h +++ b/src/shared/list.h @@ -1,7 +1,6 @@ /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ -#ifndef foolisthfoo -#define foolisthfoo +#pragma once /*** This file is part of systemd. @@ -32,23 +31,23 @@ t *name##_next, *name##_prev /* Initialize the list's head */ -#define LIST_HEAD_INIT(t,head) \ +#define LIST_HEAD_INIT(head) \ do { \ (head) = NULL; } \ while(false) /* Initialize a list item */ -#define LIST_INIT(t,name,item) \ +#define LIST_INIT(name,item) \ do { \ - t *_item = (item); \ + typeof(*(item)) *_item = (item); \ assert(_item); \ _item->name##_prev = _item->name##_next = NULL; \ } while(false) /* Prepend an item to the list */ -#define LIST_PREPEND(t,name,head,item) \ +#define LIST_PREPEND(name,head,item) \ do { \ - t **_head = &(head), *_item = (item); \ + typeof(*(head)) **_head = &(head), *_item = (item); \ assert(_item); \ if ((_item->name##_next = *_head)) \ _item->name##_next->name##_prev = _item; \ @@ -57,9 +56,9 @@ } while(false) /* Remove an item from the list */ -#define LIST_REMOVE(t,name,head,item) \ +#define LIST_REMOVE(name,head,item) \ do { \ - t **_head = &(head), *_item = (item); \ + typeof(*(head)) **_head = &(head), *_item = (item); \ assert(_item); \ if (_item->name##_next) \ _item->name##_next->name##_prev = _item->name##_prev; \ @@ -73,19 +72,19 @@ } while(false) /* Find the head of the list */ -#define LIST_FIND_HEAD(t,name,item,head) \ +#define LIST_FIND_HEAD(name,item,head) \ do { \ - t *_item = (item); \ + typeof(*(item)) *_item = (item); \ assert(_item); \ while (_item->name##_prev) \ _item = _item->name##_prev; \ (head) = _item; \ } while (false) -/* Find the head of the list */ -#define LIST_FIND_TAIL(t,name,item,tail) \ +/* Find the tail of the list */ +#define LIST_FIND_TAIL(name,item,tail) \ do { \ - t *_item = (item); \ + typeof(*(item)) *_item = (item); \ assert(_item); \ while (_item->name##_next) \ _item = _item->name##_next; \ @@ -93,9 +92,9 @@ } while (false) /* Insert an item after another one (a = where, b = what) */ -#define LIST_INSERT_AFTER(t,name,head,a,b) \ +#define LIST_INSERT_AFTER(name,head,a,b) \ do { \ - t **_head = &(head), *_a = (a), *_b = (b); \ + typeof(*(head)) **_head = &(head), *_a = (a), *_b = (b); \ assert(_b); \ if (!_a) { \ if ((_b->name##_next = *_head)) \ @@ -125,4 +124,9 @@ #define LIST_FOREACH_AFTER(name,i,p) \ for ((i) = (p)->name##_next; (i); (i) = (i)->name##_next) -#endif +/* Loop starting from p->next until p->prev. + p can be adjusted meanwhile. */ +#define LIST_LOOP_BUT_ONE(name,i,head,p) \ + for ((i) = (p)->name##_next ? (p)->name##_next : (head); \ + (i) != (p); \ + (i) = (i)->name##_next ? (i)->name##_next : (head))