[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 1/5] Add %X option to printf functions
From: |
Javier Martinez Canillas |
Subject: |
[PATCH v3 1/5] Add %X option to printf functions |
Date: |
Tue, 22 Oct 2019 10:48:10 +0200 |
From: Paulo Flabiano Smorigo <address@hidden>
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 <address@hidden>
Signed-off-by: Javier Martinez Canillas <address@hidden>
Reviewed-by: Daniel Kiper <address@hidden>
---
Changes in v3: None
Changes in v2:
- Put patch that adds the %X format specifier first in the series.
grub-core/kern/misc.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 3b633d51f4c..76e7fb22872 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -588,7 +588,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d,
grub_uint64_t *r)
static inline char *
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;
if ((long long) n < 0 && c == 'd')
@@ -603,7 +603,7 @@ grub_lltoa (char *str, int c, unsigned long long n)
do
{
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);
else
@@ -676,6 +676,7 @@ parse_printf_args (const char *fmt0, struct printf_args
*args,
{
case 'p':
case 'x':
+ case 'X':
case 'u':
case 'd':
case 'c':
@@ -762,6 +763,7 @@ parse_printf_args (const char *fmt0, struct printf_args
*args,
switch (c)
{
case 'x':
+ case 'X':
case 'u':
args->ptr[curn].type = UNSIGNED_INT + longfmt;
break;
@@ -900,6 +902,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const
char *fmt0,
c = 'x';
/* Fall through. */
case 'x':
+ case 'X':
case 'u':
case 'd':
{
--
2.21.0
- [PATCH v3 0/5] Search for specific config files using UUID, MAC and IP, Javier Martinez Canillas, 2019/10/22
- [PATCH v3 1/5] Add %X option to printf functions,
Javier Martinez Canillas <=
- [PATCH v3 2/5] net/dhcp: Consistently use hexadecimal numbers for options enum, Javier Martinez Canillas, 2019/10/22
- [PATCH v3 3/5] net/dhcp: Set net_<interface>_client{id, uuid} variables from DHCP options, Javier Martinez Canillas, 2019/10/22
- [PATCH v3 4/5] normal/main: Search for specific config files for netboot, Javier Martinez Canillas, 2019/10/22
- [PATCH v3 5/5] docs: Update info with grub.cfg netboot selection order, Javier Martinez Canillas, 2019/10/22