Add support for printing 64bit hex numbers to src/output.c
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- src/output.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/src/output.c b/src/output.c index bdde7cc..0873776 100644 --- a/src/output.c +++ b/src/output.c @@ -196,15 +196,15 @@ putsinglehex(struct putcinfo *action, u32 val)
// Output an integer in hexadecimal. static void -puthex(struct putcinfo *action, u32 val, int width, int spacepad) +puthex(struct putcinfo *action, u64 val, int width, int spacepad) { if (!width) { - u32 tmp = val; + u64 tmp = val; width = 1; while (tmp >>= 4) width++; } else if (spacepad) { - u32 tmp = val; + u64 tmp = val; u32 count = 1; while (tmp >>= 4) count++; @@ -217,7 +217,15 @@ puthex(struct putcinfo *action, u32 val, int width, int spacepad) }
switch (width) { - default: putsinglehex(action, (val >> 28) & 0xf); + default: putsinglehex(action, (val >> 60) & 0xf); + case 15: putsinglehex(action, (val >> 56) & 0xf); + case 14: putsinglehex(action, (val >> 52) & 0xf); + case 13: putsinglehex(action, (val >> 48) & 0xf); + case 12: putsinglehex(action, (val >> 44) & 0xf); + case 11: putsinglehex(action, (val >> 40) & 0xf); + case 10: putsinglehex(action, (val >> 36) & 0xf); + case 9: putsinglehex(action, (val >> 32) & 0xf); + case 8: putsinglehex(action, (val >> 28) & 0xf); case 7: putsinglehex(action, (val >> 24) & 0xf); case 6: putsinglehex(action, (val >> 20) & 0xf); case 5: putsinglehex(action, (val >> 16) & 0xf); @@ -249,6 +257,7 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) const char *n = s+1; int field_width = 0; int spacepad = 1; + int is64 = 0; for (;;) { c = GET_GLOBAL(*(u8*)n); if (!isdigit(c)) @@ -264,6 +273,12 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) n++; c = GET_GLOBAL(*(u8*)n); } + if (c == 'l') { + // long long format indicator + is64 = 1; + n++; + c = GET_GLOBAL(*(u8*)n); + } s32 val; const char *sarg; switch (c) { @@ -289,8 +304,13 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) field_width = 8; spacepad = 0; case 'x': - val = va_arg(args, s32); - puthex(action, val, field_width, spacepad); + if (is64) { + u64 val64 = va_arg(args, u64); + puthex(action, val64, field_width, spacepad); + } else { + u32 val32 = va_arg(args, u32); + puthex(action, val32, field_width, spacepad); + } break; case 'c': val = va_arg(args, int);