diff options
author | Karel Zak | 2013-12-18 10:22:32 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-11 11:35:12 +0100 |
commit | ed494c8d50d912ee7aa3cfdfc9876540d15994da (patch) | |
tree | 4c2c2ee21f601b6fe3b9fbfb005ae2f28de588c5 /lib | |
parent | libfdisk: move partition stuff to partition.c (diff) | |
download | kernel-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.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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> |