[PATCH 2/7] nvme: use table_get_value_width() in table_print_centered()
Nilay Shroff
nilay at linux.ibm.com
Thu Apr 30 03:52:23 PDT 2026
table_print_centered() open-codes the logic to determine the width of a
table value, even though a helper already exists for this purpose.
Replace the open-coded width calculation with a call to
table_get_value_width() to avoid duplication and keep the behavior
consistent across the table helpers.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
util/table.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/util/table.c b/util/table.c
index cad88d39d..1a69cd39a 100644
--- a/util/table.c
+++ b/util/table.c
@@ -53,28 +53,10 @@ static int table_get_value_width(struct value *v)
static void table_print_centered(struct value *val, int width, enum fmt_type type)
{
int i, len, left_pad, right_pad;
- char buf[64];
- switch (type) {
- case FMT_STRING:
- len = strlen(val->s);
- break;
- case FMT_INT:
- len = snprintf(buf, sizeof(buf), "%d", val->i);
- break;
- case FMT_UNSIGNED:
- len = snprintf(buf, sizeof(buf), "%u", val->u);
- break;
- case FMT_LONG:
- len = snprintf(buf, sizeof(buf), "%ld", val->ld);
- break;
- case FMT_UNSIGNED_LONG:
- len = snprintf(buf, sizeof(buf), "%lu", val->lu);
- break;
- default:
- fprintf(stderr, "Invalid format!\n");
+ len = table_get_value_width(val);
+ if (!len)
return;
- }
left_pad = (width - len) / 2;
right_pad = width - len - left_pad;
@@ -84,7 +66,7 @@ static void table_print_centered(struct value *val, int width, enum fmt_type typ
putchar(' ');
/* print value */
- switch (type) {
+ switch (val->type) {
case FMT_STRING:
printf("%s", val->s);
break;
--
2.53.0
More information about the Linux-nvme
mailing list