From: Lennart Poettering Date: Wed, 6 Jan 2021 14:51:35 +0000 (+0100) Subject: format-table: add cell type for outputting 64bit values in hex X-Git-Tag: v250-rc1~973^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=21fbf095b8aa46db8d1bd51507af666a04fa0d12;p=thirdparty%2Fsystemd.git format-table: add cell type for outputting 64bit values in hex --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 71885e6ac7d..f324962b9cd 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -272,6 +272,7 @@ static size_t table_data_size(TableDataType type, const void *data) { case TABLE_SIZE: case TABLE_INT64: case TABLE_UINT64: + case TABLE_UINT64_HEX: case TABLE_BPS: return sizeof(uint64_t); @@ -922,6 +923,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) { break; case TABLE_UINT64: + case TABLE_UINT64_HEX: buffer.uint64 = va_arg(ap, uint64_t); data = &buffer.uint64; break; @@ -1257,6 +1259,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t return CMP(a->uint32, b->uint32); case TABLE_UINT64: + case TABLE_UINT64_HEX: return CMP(a->uint64, b->uint64); case TABLE_PERCENT: @@ -1608,6 +1611,18 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas break; } + case TABLE_UINT64_HEX: { + _cleanup_free_ char *p; + + p = new(char, 16 + 1); + if (!p) + return NULL; + + sprintf(p, "%" PRIx64, d->uint64); + d->formatted = TAKE_PTR(p); + break; + } + case TABLE_PERCENT: { _cleanup_free_ char *p = NULL; @@ -2503,6 +2518,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) { return json_variant_new_unsigned(ret, d->uint32); case TABLE_UINT64: + case TABLE_UINT64_HEX: return json_variant_new_unsigned(ret, d->uint64); case TABLE_PERCENT: diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 411922acf77..e31c71f7927 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -33,6 +33,7 @@ typedef enum TableDataType { TABLE_UINT16, TABLE_UINT32, TABLE_UINT64, + TABLE_UINT64_HEX, TABLE_PERCENT, TABLE_IFINDEX, TABLE_IN_ADDR, /* Takes a union in_addr_union (or a struct in_addr) */