Skip to content

Commit

Permalink
Implement console printf
Browse files Browse the repository at this point in the history
  • Loading branch information
kotovalexarian committed Dec 3, 2022
1 parent 64e324e commit 3bf16b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/drivers/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
}

0 comments on commit 3bf16b6

Please sign in to comment.