Jelajahi Sumber

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 <claustbp@google.com>
Change-Id: Ib7fefaec0babb783def614ea23521f482fa4a28a
Claus Pedersen 1 tahun lalu
induk
melakukan
e0b6826e44
2 mengubah file dengan 13 tambahan dan 11 penghapusan
  1. 9 1
      drivers/console/multi_console.c
  2. 4 10
      lib/libc/putchar.c

+ 9 - 1
drivers/console/multi_console.c

@@ -6,6 +6,7 @@
 
 #include <assert.h>
 #include <stddef.h>
+#include <stdlib.h>
 
 #include <drivers/console.h>
 
@@ -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;

+ 4 - 10
lib/libc/putchar.c

@@ -6,15 +6,9 @@
 
 #include <stdio.h>
 
-#include <drivers/console.h>
-
-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")));