From b85611dae8ac13aa4c1eb37377a58cd77d04424e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2023 12:10:21 +1000 Subject: [PATCH] shared/libc/printf: Fix stdout destination for putchar and puts. These functions should output to the same location as printf in this file. Signed-off-by: Damien George --- shared/libc/printf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/shared/libc/printf.c b/shared/libc/printf.c index 6b5373188f..715181229e 100644 --- a/shared/libc/printf.c +++ b/shared/libc/printf.c @@ -72,16 +72,14 @@ int vprintf(const char *fmt, va_list ap) { // need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a') int putchar(int c) { char chr = c; - mp_hal_stdout_tx_strn_cooked(&chr, 1); + MICROPY_INTERNAL_PRINTF_PRINTER->print_strn(MICROPY_INTERNAL_PRINTF_PRINTER->data, &chr, 1); return chr; } // need this because gcc optimises printf("string\n") -> puts("string") int puts(const char *s) { - mp_hal_stdout_tx_strn_cooked(s, strlen(s)); - char chr = '\n'; - mp_hal_stdout_tx_strn_cooked(&chr, 1); - return 1; + MICROPY_INTERNAL_PRINTF_PRINTER->print_strn(MICROPY_INTERNAL_PRINTF_PRINTER->data, s, strlen(s)); + return putchar('\n'); // will return 10, which is >0 per specs of puts } typedef struct _strn_print_env_t {