From 88b28a7b178cf8c4d611725021862035629fbbcd Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Thu, 14 May 2020 10:09:36 +1000 Subject: [PATCH] console: Improve putchar(), add puts() Make putchar() match a standard prototype and add puts() Also make puts() add carriage returns before linefeeds so the users don't have to do it all over the place. Signed-off-by: Benjamin Herrenschmidt --- hello_world/console.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hello_world/console.c b/hello_world/console.c index 6c1c311..66a7d3a 100644 --- a/hello_world/console.c +++ b/hello_world/console.c @@ -98,12 +98,13 @@ int getchar(void) return potato_uart_read(); } -void putchar(unsigned char c) +int putchar(int c) { while (potato_uart_tx_full()) /* Do Nothing */; potato_uart_write(c); + return c; } void putstr(const char *str, unsigned long len) @@ -113,6 +114,19 @@ void putstr(const char *str, unsigned long len) } } +int puts(const char *str) +{ + unsigned int i; + + for (i = 0; *str; i++) { + char c = *(str++); + if (c == 10) + putchar(13); + putchar(c); + } + return 0; +} + size_t strlen(const char *s) { size_t len = 0;