feat: refactor to use gcc types
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "kprintf.h"
|
||||
#include "libc.h"
|
||||
#include <libc/string.h>
|
||||
#include <libc/va_list.h>
|
||||
#include <stdarg.h>
|
||||
#include <kprint.h>
|
||||
#include <libk.h>
|
||||
#include <types.h>
|
||||
@@ -13,32 +13,32 @@
|
||||
/*
|
||||
* Integer to string
|
||||
*/
|
||||
void print_int(u32 value, u32 width, char *buf, u32 *ptr, u8 base) {
|
||||
// u32 in binary is 32 digits, so never longer than 33 digits
|
||||
void print_int(uint32_t value, uint32_t width, char *buf, uint32_t *ptr, uint8_t base) {
|
||||
// uint32_t in binary is 32 digits, so never longer than 33 digits
|
||||
char msg[33];
|
||||
itoa(value, msg, base);
|
||||
u32 digits = strlen(msg);
|
||||
uint32_t digits = strlen(msg);
|
||||
if (digits < width) {
|
||||
for (u32 i = 0; i < (width - digits); ++i) {
|
||||
for (uint32_t i = 0; i < (width - digits); ++i) {
|
||||
buf[*ptr] = '0';
|
||||
*ptr += 1;
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < digits; ++i) {
|
||||
for (uint32_t i = 0; i < digits; ++i) {
|
||||
buf[*ptr] = msg[i];
|
||||
*ptr += 1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 vasprintf(char *buf, const char *fmt, va_list args) {
|
||||
u32 ptr = 0;
|
||||
uint32_t vasprintf(char *buf, const char *fmt, va_list args) {
|
||||
uint32_t ptr = 0;
|
||||
for (int i = 0; i < strlen(fmt); ++i) {
|
||||
if (fmt[i] != '%') {
|
||||
buf[ptr++] = fmt[i];
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
u32 arg_width = 0;
|
||||
uint32_t arg_width = 0;
|
||||
while (fmt[i] >= '0' && fmt[i] <= '9') {
|
||||
arg_width *= 10;
|
||||
arg_width += fmt[i] - '0';
|
||||
@@ -56,10 +56,10 @@ u32 vasprintf(char *buf, const char *fmt, va_list args) {
|
||||
buf[ptr++] = (char) va_arg(args, int);
|
||||
break;
|
||||
case 'x':
|
||||
print_int((u32) va_arg(args, u32), arg_width, buf, &ptr, 16);
|
||||
print_int((uint32_t) va_arg(args, uint32_t), arg_width, buf, &ptr, 16);
|
||||
break;
|
||||
case 'd':
|
||||
print_int((u32) va_arg(args, u32), arg_width, buf, &ptr, 10);
|
||||
print_int((uint32_t) va_arg(args, uint32_t), arg_width, buf, &ptr, 10);
|
||||
break;
|
||||
case '%':
|
||||
buf[ptr++] = '%';
|
||||
|
||||
Reference in New Issue
Block a user