]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add new uint32_t hex field type
authorLennart Poettering <lennart@poettering.net>
Fri, 7 Jul 2023 15:26:33 +0000 (17:26 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 20 Oct 2023 14:55:15 +0000 (15:55 +0100)
src/shared/format-table.c
src/shared/format-table.h

index 20e1675d0decabc606e20ca5724c7ac15062fa7f..946d29b8702f23939f2952f8a91d1ea6dc38f6da 100644 (file)
@@ -318,6 +318,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
 
         case TABLE_INT32:
         case TABLE_UINT32:
+        case TABLE_UINT32_HEX:
                 return sizeof(uint32_t);
 
         case TABLE_INT16:
@@ -981,6 +982,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
                 }
 
                 case TABLE_UINT32:
+                case TABLE_UINT32_HEX:
                         buffer.uint32 = va_arg(ap, uint32_t);
                         data = &buffer.uint32;
                         break;
@@ -1365,6 +1367,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
                         return CMP(a->uint16, b->uint16);
 
                 case TABLE_UINT32:
+                case TABLE_UINT32_HEX:
                         return CMP(a->uint32, b->uint32);
 
                 case TABLE_UINT64:
@@ -1756,6 +1759,18 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
                 break;
         }
 
+        case TABLE_UINT32_HEX: {
+                _cleanup_free_ char *p = NULL;
+
+                p = new(char, 8 + 1);
+                if (!p)
+                        return NULL;
+
+                sprintf(p, "%" PRIx32, d->uint32);
+                d->formatted = TAKE_PTR(p);
+                break;
+        }
+
         case TABLE_UINT64: {
                 _cleanup_free_ char *p = NULL;
 
@@ -2689,6 +2704,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
                 return json_variant_new_unsigned(ret, d->uint16);
 
         case TABLE_UINT32:
+        case TABLE_UINT32_HEX:
                 return json_variant_new_unsigned(ret, d->uint32);
 
         case TABLE_UINT64:
index 742d5e3ae251d826c738949d7ee050b5085613a5..7653ad3243bd292b9fa55a1325eed3213ca5eaa3 100644 (file)
@@ -40,6 +40,7 @@ typedef enum TableDataType {
         TABLE_UINT8,
         TABLE_UINT16,
         TABLE_UINT32,
+        TABLE_UINT32_HEX,
         TABLE_UINT64,
         TABLE_UINT64_HEX,
         TABLE_PERCENT,