Luna/kernel/src/arch/Serial.cpp

38 lines
734 B
C++
Raw Normal View History

2022-11-13 09:30:10 +00:00
#include "arch/Serial.h"
2022-12-07 10:40:02 +00:00
#include <luna/Result.h>
#include <luna/Format.h>
2022-12-07 10:40:02 +00:00
#include <stdarg.h>
2022-11-13 09:30:10 +00:00
namespace Serial
{
void write(const char* str, usize size)
2022-11-13 09:30:10 +00:00
{
while (size--) putchar(*str++);
}
void print(const char* str)
{
while (*str) putchar(*str++);
}
void println(const char* str)
{
print(str);
putchar('\n');
}
2022-11-19 11:30:36 +00:00
2022-11-19 15:13:25 +00:00
Result<usize> printf(const char* format, ...)
2022-11-19 11:30:36 +00:00
{
va_list ap;
va_start(ap, format);
2022-11-19 15:13:25 +00:00
auto rc = cstyle_format(
2022-11-19 11:30:36 +00:00
format,
2022-11-19 15:13:25 +00:00
[](char c, void*) -> Result<void> {
2022-11-19 11:30:36 +00:00
putchar(c);
2022-11-19 15:13:25 +00:00
return {};
2022-11-19 11:30:36 +00:00
},
nullptr, ap);
va_end(ap);
2022-11-19 15:13:25 +00:00
return rc;
2022-11-19 11:30:36 +00:00
}
2022-11-13 09:30:10 +00:00
}