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 <damien@micropython.org>
This commit is contained in:
Damien George 2023-05-31 12:10:21 +10:00
parent ed7a3b11d9
commit b85611dae8
1 changed files with 3 additions and 5 deletions

View File

@ -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 {