summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-11 15:01:46 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-11-13 17:36:22 +0900
commitd3a3a0fae3c04d760f5d94048e83c8a0a6cd5f60 (patch)
tree40bd7159ad7a8cc7f3e11d51a9e694913e8f1588 /src
parent8f6469cbf9c217a0d9c0e17b63cc49ede00ddf05 (diff)
downloadsystemd-d3a3a0fae3c04d760f5d94048e83c8a0a6cd5f60.tar.gz
format-table: teach table_add_cell_stringf_full() to generate TABLE_FIELD/TABLE_HEADER cells, too
Diffstat (limited to 'src')
-rw-r--r--src/shared/format-table.c7
-rw-r--r--src/shared/format-table.h3
2 files changed, 7 insertions, 3 deletions
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index 82744a3f96..1c1db2f43a 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -507,18 +507,21 @@ int table_add_cell_full(
return 0;
}
-int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, ...) {
+int table_add_cell_stringf_full(Table *t, TableCell **ret_cell, TableDataType dt, const char *format, ...) {
_cleanup_free_ char *buffer = NULL;
va_list ap;
int r;
+ assert(t);
+ assert(IN_SET(dt, TABLE_STRING, TABLE_PATH, TABLE_FIELD, TABLE_HEADER));
+
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);
+ return table_add_cell(t, ret_cell, dt, buffer);
}
int table_fill_empty(Table *t, size_t until_column) {
diff --git a/src/shared/format-table.h b/src/shared/format-table.h
index c1fada77c7..e835692c6f 100644
--- a/src/shared/format-table.h
+++ b/src/shared/format-table.h
@@ -89,7 +89,8 @@ 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_MAX, SIZE_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
}
-int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, ...) _printf_(3, 4);
+int table_add_cell_stringf_full(Table *t, TableCell **ret_cell, TableDataType type, const char *format, ...) _printf_(4, 5);
+#define table_add_cell_stringf(t, ret_cell, format, ...) table_add_cell_stringf_full(t, ret_cell, TABLE_STRING, format, __VA_ARGS__)
int table_fill_empty(Table *t, size_t until_column);