]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/list: add list_last_entry()
authorKarel Zak <kzak@redhat.com>
Tue, 18 Dec 2012 13:49:21 +0000 (14:49 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Dec 2012 14:00:03 +0000 (15:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/list.h
lib/tt.c

index 414d356ba16854d28090de2430fbeede68f69b59..e9ed0c4cd37120fd6b6d83a891874a2b2a7dc406 100644 (file)
@@ -127,11 +127,11 @@ _INLINE_ int list_empty(struct list_head *head)
 }
 
 /**
- * list_last_entry - tests whether is entry last in the list
+ * list_entry_is_last - tests whether is entry last in the list
  * @entry:     the entry to test.
  * @head:      the list to test.
  */
-_INLINE_ int list_last_entry(struct list_head *entry, struct list_head *head)
+_INLINE_ int list_entry_is_last(struct list_head *entry, struct list_head *head)
 {
        return head->prev == entry;
 }
@@ -171,6 +171,9 @@ _INLINE_ void list_splice(struct list_head *list, struct list_head *head)
 #define list_first_entry(head, type, member) \
        ((head) && (head)->next != (head) ? list_entry((head)->next, type, member) : NULL)
 
+#define list_last_entry(head, type, member) \
+       ((head) && (head)->prev != (head) ? list_entry((head)->prev, type, member) : NULL)
+
 /**
  * list_for_each - iterate over elements in a list
  * @pos:       the &struct list_head to use as a loop counter.
index 54a452417d5b70ccde4990de0407151cc71862b1..310c47e9fac93f6dcd73b2fbd467e15a1bcdbbf4 100644 (file)
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -50,7 +50,7 @@ static const struct tt_symbols utf8_tt_symbols = {
 #endif /* !HAVE_WIDECHAR */
 
 #define is_last_column(_tb, _cl) \
-               list_last_entry(&(_cl)->cl_columns, &(_tb)->tb_columns)
+               list_entry_is_last(&(_cl)->cl_columns, &(_tb)->tb_columns)
 
 /*
  * Counts number of cells in multibyte string. For all control and
@@ -401,7 +401,7 @@ static char *line_get_ascii_art(struct tt_line *ln, char *buf, size_t *bufsz)
        if (!buf)
                return NULL;
 
-       if (list_last_entry(&ln->ln_children, &ln->parent->ln_branch))
+       if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
                art = "  ";
        else
                art = ln->table->symbols->vert;
@@ -445,7 +445,7 @@ static char *line_get_data(struct tt_line *ln, struct tt_column *cl,
 
        if (!ln->parent)
                snprintf(p, bufsz, "%s", data);                 /* root node */
-       else if (list_last_entry(&ln->ln_children, &ln->parent->ln_branch))
+       else if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
                snprintf(p, bufsz, "%s%s", sym->right, data);   /* last chaild */
        else
                snprintf(p, bufsz, "%s%s", sym->branch, data);  /* any child */