refactor(io): change functions names

This commit is contained in:
2026-01-26 15:21:39 +01:00
parent 94636f8c09
commit 172da6cf07
2 changed files with 13 additions and 27 deletions

View File

@@ -8,7 +8,6 @@
#define va_end __builtin_va_end
#define va_arg __builtin_va_arg
void r_printf(const char *fmt, ...);
size_t r_strlen(const char *str);
void kprintf(const char *fmt, ...);
#endif

View File

@@ -1,14 +1,15 @@
#include "../include/io.h"
#include "../include/string.h"
void k_putchar(char ch);
void kputchar(char ch);
void r_printf(const char *fmt, ...) {
void kprintf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
while (*fmt) {
if (*fmt != '%') {
k_putchar(*fmt);
kputchar(*fmt);
fmt++;
continue;
}
@@ -18,13 +19,13 @@ void r_printf(const char *fmt, ...) {
switch (*fmt) {
case '\0': {
/* Simply print the char */
k_putchar('%');
kputchar('%');
goto end;
}
case '%': {
/* Print '%' */
k_putchar('%');
kputchar('%');
break;
}
@@ -32,7 +33,7 @@ void r_printf(const char *fmt, ...) {
/* Print a NULL-terminated string */
const char *s = va_arg(args, const char *);
while (*s) {
k_putchar(*s);
kputchar(*s);
s++;
}
@@ -43,7 +44,7 @@ void r_printf(const char *fmt, ...) {
int value = va_arg(args, int);
unsigned magnitude = value;
if (value < 0) {
k_putchar('-');
kputchar('-');
magnitude = -magnitude;
}
@@ -53,12 +54,9 @@ void r_printf(const char *fmt, ...) {
}
while (divisor > 0) {
k_putchar('0' + magnitude);
k_putchar('0' + magnitude / divisor);
kputchar('0' + magnitude / divisor);
magnitude %= divisor;
k_putchar('0' + magnitude);
divisor /= 10;
k_putchar('0' + magnitude);
}
break;
@@ -69,14 +67,14 @@ void r_printf(const char *fmt, ...) {
for (int i = 7; i >= 0; --i) {
unsigned nibble = (value >> (i * 4)) & 0xF;
/* From a char array we get the nibble position */
k_putchar("0123456789ABCDEF"[nibble]);
kputchar("0123456789ABCDEF"[nibble]);
}
}
default: {
const char *str = "NOT IMPLEMENTED";
size_t len = r_strlen(str);
size_t len = kstrlen(str);
for (size_t i = 0; i < len; ++i) {
k_putchar(str[i]);
kputchar(str[i]);
}
}
}
@@ -87,14 +85,3 @@ void r_printf(const char *fmt, ...) {
end:
va_end(args);
}
size_t r_strlen(const char *str) {
size_t len = 0;
while (*str) {
len++;
str++;
}
return len;
}