kern: Add %X option to printf functions

The printf(3) function has support for the %X format specifier, to output
an unsigned hexadecimal integer in uppercase.

This can be achived in GRUB using the %x format specifier in grub_printf()
and calling grub_toupper(), but it is more convenient if there is support
for %X in grub_printf().

Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Paulo Flabiano Smorigo 2020-01-22 12:01:52 +01:00 committed by Daniel Kiper
parent aa096037ae
commit 8c2c35dcc0

View file

@ -588,7 +588,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
static inline char * static inline char *
grub_lltoa (char *str, int c, unsigned long long n) grub_lltoa (char *str, int c, unsigned long long n)
{ {
unsigned base = (c == 'x') ? 16 : 10; unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
char *p; char *p;
if ((long long) n < 0 && c == 'd') if ((long long) n < 0 && c == 'd')
@ -603,7 +603,7 @@ grub_lltoa (char *str, int c, unsigned long long n)
do do
{ {
unsigned d = (unsigned) (n & 0xf); unsigned d = (unsigned) (n & 0xf);
*p++ = (d > 9) ? d + 'a' - 10 : d + '0'; *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
} }
while (n >>= 4); while (n >>= 4);
else else
@ -676,6 +676,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
{ {
case 'p': case 'p':
case 'x': case 'x':
case 'X':
case 'u': case 'u':
case 'd': case 'd':
case 'c': case 'c':
@ -762,6 +763,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
switch (c) switch (c)
{ {
case 'x': case 'x':
case 'X':
case 'u': case 'u':
args->ptr[curn].type = UNSIGNED_INT + longfmt; args->ptr[curn].type = UNSIGNED_INT + longfmt;
break; break;
@ -900,6 +902,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
c = 'x'; c = 'x';
/* Fall through. */ /* Fall through. */
case 'x': case 'x':
case 'X':
case 'u': case 'u':
case 'd': case 'd':
{ {