]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/tt: add tb_get_nlines()
authorKarel Zak <kzak@redhat.com>
Fri, 22 Nov 2013 12:31:15 +0000 (13:31 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:12 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/tt.h
lib/tt.c

index 11bd81e4bd8326b2664a4afbc63e0aae08905115..ce76524ac70175b7b5c651cce5d5a38f983ba28f 100644 (file)
@@ -95,6 +95,8 @@ extern int tt_line_set_userdata(struct tt_line *ln, void *data);
 extern void tt_fputs_quoted(const char *data, FILE *out);
 extern void tt_fputs_nonblank(const char *data, FILE *out);
 
+extern size_t tb_get_nlines(struct tt *tb);
+
 static inline int tt_is_empty(struct tt *tb)
 {
        return !tb || list_empty(&tb->tb_lines);
index 46fc00e8786edae42b6b93d2d2f6218dedcd8af9..e94524e8615bc5eacec3625b60fa3817c2b2f945 100644 (file)
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -223,6 +223,19 @@ void tt_set_stream(struct tt *tb, FILE *out)
        tb->out = out;
 }
 
+size_t tb_get_nlines(struct tt *tb)
+{
+       struct list_head *p;
+       size_t ct = 0;
+
+       if (tt_is_empty(tb))
+               return 0;
+
+       list_for_each(p, &tb->tb_lines)
+               ct++;
+       return ct;
+}
+
 void tt_remove_lines(struct tt *tb)
 {
        if (!tb)