From 3bf16b63e0aa4c51d2b264bb13098afb68d3ac14 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 3 Dec 2022 20:35:45 +0400 Subject: [PATCH] Implement console printf --- include/drivers/console.h | 3 +++ src/console.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/drivers/console.h b/include/drivers/console.h index a3b5609..d8e108e 100644 --- a/include/drivers/console.h +++ b/include/drivers/console.h @@ -13,6 +13,9 @@ void drivers_console_print(const char *s); void drivers_console_puts(const char *s); void drivers_console_write(const char *data, size_t size); +__attribute__((format(printf, 1, 2))) +void drivers_console_printf(const char *format, ...); + #ifdef __cplusplus } #endif diff --git a/src/console.c b/src/console.c index 8c13f7e..42ff732 100644 --- a/src/console.c +++ b/src/console.c @@ -4,8 +4,18 @@ #include +#include #include +int kernaux_vfprintf( + void (*out)(char, void*), + void *data, + const char* format, + va_list va +); + +static void file_putc(char c, void *arg); + void drivers_console_putc(const char c) { #if defined(ASM_X86) @@ -22,6 +32,14 @@ void drivers_console_print(const char *const s) } } +void drivers_console_printf(const char *format, ...) +{ + va_list va; + va_start(va, format); + kernaux_vfprintf(file_putc, NULL, format, va); + va_end(va); +} + void drivers_console_puts(const char *const s) { drivers_console_print(s); @@ -34,3 +52,8 @@ void drivers_console_write(const char *const data, const size_t size) drivers_console_putc(data[i]); } } + +void file_putc(char c, void *arg __attribute__((unused))) +{ + drivers_console_putc(c); +}