]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add cell type for outputting 64bit values in hex
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Jan 2021 14:51:35 +0000 (15:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2021 08:29:43 +0000 (10:29 +0200)
src/shared/format-table.c
src/shared/format-table.h

index 71885e6ac7d701c9ecab6de790db9c182f291de8..f324962b9cd8b05195db792cd5b304caf83d650a 100644 (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:
index 411922acf77076bd1bf4f686832603115e22b1ae..e31c71f7927efe3ec75cc13fad4c50272e6bf9a2 100644 (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) */