From: Karel Zak Date: Fri, 22 Nov 2013 12:31:15 +0000 (+0100) Subject: lib/tt: add tb_get_nlines() X-Git-Tag: v2.25-rc1~536 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=575a1de03a38bdcc9c9697041633732ea34f1021;p=thirdparty%2Futil-linux.git lib/tt: add tb_get_nlines() Signed-off-by: Karel Zak --- diff --git a/include/tt.h b/include/tt.h index 11bd81e4bd..ce76524ac7 100644 --- a/include/tt.h +++ b/include/tt.h @@ -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); diff --git a/lib/tt.c b/lib/tt.c index 46fc00e878..e94524e861 100644 --- 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)