Luna/kernel/src/arch/Serial.cpp
apio 814672c771
All checks were successful
continuous-integration/drone/push Build is passing
Remove some redundant error propagation
Why can printing to the serial port or format onto a string fail?
Even if cstyle_format returns Result<usize>, we shouldn't always follow suit.
2022-12-16 18:32:29 +01:00

39 lines
894 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)
.expect_value("Sanity check failed in Serial::printf: Should never fail");
va_end(ap);
return rc;
}
}