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>
extern void tt_free_table(struct tt *tb);
extern void tt_remove_lines(struct tt *tb);
extern int tt_print_table(struct tt *tb);
+extern int tt_print_table_to_string(struct tt *tb, char **data);
extern void tt_set_stream(struct tt *tb, FILE *out);
extern struct tt_column *tt_define_column(struct tt *tb, const char *name,
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>