From e2a24e574630886d1033be9111efe5b8b3ed7f94 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 27 Mar 2019 01:29:07 +0100 Subject: [PATCH] AK: printf() should support %#x and %#o. --- AK/printf.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/AK/printf.cpp b/AK/printf.cpp index ccef0e6d67f..31803c97968 100644 --- a/AK/printf.cpp +++ b/AK/printf.cpp @@ -193,6 +193,7 @@ template bool zeroPad = false; unsigned fieldWidth = 0; unsigned long_qualifiers = 0; + bool alternate_form = 0; if (*p == '%' && *(p + 1)) { one_more: ++p; @@ -214,7 +215,13 @@ one_more: } if (*p == 'l') { ++long_qualifiers; - goto one_more; + if (*(p + 1)) + goto one_more; + } + if (*p == '#') { + alternate_form = true; + if (*(p + 1)) + goto one_more; } switch( *p ) { @@ -247,10 +254,19 @@ one_more: break; case 'o': + if (alternate_form) { + putch(bufptr, '0'); + ++ret; + } ret += print_octal_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth); break; case 'x': + if (alternate_form) { + putch(bufptr, '0'); + putch(bufptr, 'x'); + ret += 2; + } ret += print_hex(putch, bufptr, va_arg(ap, dword), 8); break;