lib: Fix '%X' formatting

This commit is contained in:
2026-10-27 23:15:27 +01:00
parent 74d53ca5dd
commit 254f005c4f
3 changed files with 15 additions and 2 deletions
+1
View File
@@ -12,3 +12,4 @@ void* memset(void* dest, int value, size_t n);
char* strncpy(char* restrict dst, const char* restrict src, size_t len);
int strcmp(const char* str1, const char* str2);
int strncmp(const char* str1, const char* str2, size_t len);
char* strchr(const char* s, int c);
+8 -2
View File
@@ -234,6 +234,12 @@ check_fmt:
lutoa(va_arg(args, uint64_t), number, 16);
break;
}
if (*fmt == 'X') {
for (char* c = number; *c; c++) {
if (*c >= 'a' && *c <= 'f')
*c -= 'a' - 'A';
}
}
print_num:
const char* digits = number;
char sign = 0;
@@ -260,7 +266,7 @@ print_num:
if (sign)
callback(ctx, &sign, 1);
if (write_prefix)
callback(ctx, "0x", 2);
callback(ctx, *fmt == 'X' ? "0X" : "0x", 2);
print_pad(callback, ctx, '0', zeros);
callback(ctx, digits, len);
if (left_align)
@@ -285,7 +291,7 @@ print_num:
callback(ctx, number, len);
fmt++;
written += len;
written += offset + len;
break;
}
// The number of characters written so far is stored in the pointed location.
+6
View File
@@ -5,6 +5,9 @@
[[__hot]]
size_t strlen(const char* str) {
if (!str)
return 0;
size_t result = 0;
while (*str++) {
result++;
@@ -14,6 +17,9 @@ size_t strlen(const char* str) {
[[__hot]]
size_t strnlen(const char* str, size_t len) {
if (!str || len == 0)
return 0;
size_t result = 0;
while (result < len && *str++) {
result++;