]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
table: add teble_add_string_cell()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 May 2019 10:59:06 +0000 (19:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 29 May 2019 05:21:19 +0000 (14:21 +0900)
src/shared/format-table.c
src/shared/format-table.h

index 4f4a84d7494e259726b4e52581e9fb90e9d4a85b..de72bf02f32c7caf987ee15ec8e7af5fdbb684f6 100644 (file)
@@ -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;
 
index 85e3afce4c3511e41c3c949af50f05d1e2334740..5a52c43e25a45b167c8c07c8cd62fdb4db696437 100644 (file)
@@ -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);