Kernel, libc: Implement %p in *printf()

So we can avoid writing (unsigned long)ptr or (uint64_t)ptr everywhere when wanting to print a pointer.
This commit is contained in:
apio 2022-10-08 18:07:33 +02:00
parent 247645d301
commit c67079dd74
2 changed files with 16 additions and 0 deletions

View File

@ -159,6 +159,14 @@ static int internal_printf(const char* format, PutString put_string_callback, ss
}
break;
}
case 'p': {
char result[25];
ultoa(va_arg(ap, uint64_t), result, 16);
if (buffer_insert_index + strlen(result) > 1024) flush_buffer();
memcpy(buffer + buffer_insert_index, result, strlen(result));
buffer_insert_index += strlen(result);
if (buffer_insert_index == 1024) flush_buffer();
}
case 's': {
const char* str = va_arg(ap, const char*);
while (strlen(str) > 1024)

View File

@ -242,6 +242,14 @@ static int internal_printf(const char* format, PutString put_string_callback, ss
}
break;
}
case 'p': {
char result[25];
__unsignedtoa<unsigned long>(va_arg(ap, uint64_t), result, 16);
if (buffer_insert_index + strlen(result) > 1024) flush_buffer();
memcpy(buffer + buffer_insert_index, result, strlen(result));
buffer_insert_index += strlen(result);
if (buffer_insert_index == 1024) flush_buffer();
}
case 's': {
const char* str = va_arg(ap, const char*);
while (strlen(str) > 1024)