From: Yu Watanabe Date: Thu, 23 May 2019 10:59:06 +0000 (+0900) Subject: table: add teble_add_string_cell() X-Git-Tag: v243-rc1~342^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5896e03c6f0a39a0fe75ddc3cfe54af1f7dc4113;p=thirdparty%2Fsystemd.git table: add teble_add_string_cell() --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 4f4a84d7494..de72bf02f32 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -380,6 +380,20 @@ int table_add_cell_full( return 0; } +int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, ...) { + _cleanup_free_ char *buffer = NULL; + va_list ap; + int r; + + va_start(ap, format); + r = vasprintf(&buffer, format, ap); + va_end(ap); + if (r < 0) + return -ENOMEM; + + return table_add_cell(t, ret_cell, TABLE_STRING, buffer); +} + int table_dup_cell(Table *t, TableCell *cell) { size_t i; diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 85e3afce4c3..5a52c43e25a 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -36,6 +36,7 @@ int table_add_cell_full(Table *t, TableCell **ret_cell, TableDataType type, cons static inline int table_add_cell(Table *t, TableCell **ret_cell, TableDataType type, const void *data) { return table_add_cell_full(t, ret_cell, type, data, (size_t) -1, (size_t) -1, (unsigned) -1, (unsigned) -1, (unsigned) -1); } +int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, ...) _printf_(3, 4); int table_dup_cell(Table *t, TableCell *cell);