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_end __builtin_va_end
#define va_arg __builtin_va_arg #define va_arg __builtin_va_arg
void r_printf(const char *fmt, ...); void kprintf(const char *fmt, ...);
size_t r_strlen(const char *str);
#endif #endif

View File

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