From e0b6826e44116fb6f261df1fc06b269721d29999 Mon Sep 17 00:00:00 2001 From: Claus Pedersen Date: Mon, 12 Sep 2022 23:47:10 +0000 Subject: [PATCH] refactor(console): move putchar() to console driver Moving putchar() out of libc and adding a weak dummy implementation in libc. This is to remove libc's dependencies to the platform driver. Signed-off-by: Claus Pedersen Change-Id: Ib7fefaec0babb783def614ea23521f482fa4a28a --- drivers/console/multi_console.c | 10 +++++++++- lib/libc/putchar.c | 14 ++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/console/multi_console.c b/drivers/console/multi_console.c index a68a018e7..e3fb749ba 100644 --- a/drivers/console/multi_console.c +++ b/drivers/console/multi_console.c @@ -6,6 +6,7 @@ #include #include +#include #include @@ -96,10 +97,17 @@ int console_putc(int c) if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err)) err = ret; } - return err; } +int putchar(int c) +{ + if (console_putc(c) == 0) + return c; + else + return EOF; +} + int console_getc(void) { int err = ERROR_NO_VALID_CONSOLE; diff --git a/lib/libc/putchar.c b/lib/libc/putchar.c index 037e28ac4..3472b2436 100644 --- a/lib/libc/putchar.c +++ b/lib/libc/putchar.c @@ -6,15 +6,9 @@ #include -#include - -int putchar(int c) +int __putchar(int c) { - int res; - if (console_putc((unsigned char)c) >= 0) - res = c; - else - res = EOF; - - return res; + return c; } + +int putchar(int c) __attribute__((weak,alias("__putchar")));