summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2013-12-18 10:22:32 +0100
committerKarel Zak2014-03-11 11:35:12 +0100
commited494c8d50d912ee7aa3cfdfc9876540d15994da (patch)
tree4c2c2ee21f601b6fe3b9fbfb005ae2f28de588c5 /lib
parentlibfdisk: move partition stuff to partition.c (diff)
downloadkernel-qcow2-util-linux-ed494c8d50d912ee7aa3cfdfc9876540d15994da.tar.gz
kernel-qcow2-util-linux-ed494c8d50d912ee7aa3cfdfc9876540d15994da.tar.xz
kernel-qcow2-util-linux-ed494c8d50d912ee7aa3cfdfc9876540d15994da.zip
include/tt: add function to convert table to string
Note that open_memstream() is POSIX-1.2008, so it's possible than not all libc have already implemented this function. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/tt.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/tt.c b/lib/tt.c
index 3cca4817f..60534dfa3 100644
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -986,6 +986,32 @@ int tt_print_table(struct tt *tb)
return 0;
}
+
+/*
+ * @tb: table
+ *
+ * Prints the table to string
+ */
+int tt_print_table_to_string(struct tt *tb, char **data)
+{
+ FILE *stream;
+ size_t sz;
+
+ if (!tb)
+ return -EINVAL;
+
+ /* create a streem for output */
+ stream = open_memstream(data, &sz);
+ if (!stream)
+ return -ENOMEM;
+
+ tt_set_stream(tb, stream);
+ tt_print_table(tb);
+ fclose(stream);
+
+ return 0;
+}
+
#ifdef TEST_PROGRAM
#include <errno.h>