Luna/kernel/src/arch/Serial.cpp
apio de38eb6877
All checks were successful
continuous-integration/drone/push Build is passing
luna: Remove pure_cstyle_format
It was causing a lot of code duplication. If someone doesn't have errors, just return {} from the callback and unwrap the Result.
2023-03-02 13:38:21 +01:00

40 lines
830 B
C++

#include "arch/Serial.h"
#include <luna/Format.h>
#include <luna/Result.h>
#include <stdarg.h>
namespace Serial
{
void write(const char* str, usize size)
{
while (size--) putchar((u8)*str++);
}
void print(const char* str)
{
while (*str) putchar((u8)*str++);
}
void println(const char* str)
{
print(str);
putchar('\n');
}
usize printf(const char* format, ...)
{
va_list ap;
va_start(ap, format);
auto rc = cstyle_format(
format,
[](char c, void*) -> Result<void> {
putchar((u8)c);
return {};
},
nullptr, ap)
.value();
va_end(ap);
return rc;
}
}