1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 07:51:21 +03:00

format-table: add cell type for outputting 64bit values in hex

This commit is contained in:
Lennart Poettering 2021-01-06 15:51:35 +01:00
parent bc773fcb35
commit 21fbf095b8
2 changed files with 17 additions and 0 deletions

View File

@ -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:

View File

@ -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) */