1
0
Fork 0
mirror of https://github.com/tailix/drivers.git synced 2024-11-20 11:06:32 -05:00

Implement console printf

This commit is contained in:
Alex Kotov 2022-12-03 20:35:45 +04:00
parent 64e324efb3
commit 3bf16b63e0
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 26 additions and 0 deletions

View file

@ -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

View file

@ -4,8 +4,18 @@
#include <drivers/console.h>
#include <stdarg.h>
#include <stddef.h>
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);
}