From 9ac7df5ddcd5c9aa3eb6461f01b0edcb6a20ba62 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 21 Jun 2024 00:24:31 +0800 Subject: [PATCH] libc: picolibc: fputc should return the value it has written According to the documentations: - en.cppreference.com/w/c/io/fputc - pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html Return value - On success, returns the written character. - On failure, returns EOF and sets the error indicator (see ferror()) on stream. This commit changes it to return the written value on success, and EOF if failed, which is the same as minimal libc, but the error indicator is still not set. Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- lib/libc/picolibc/stdio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/libc/picolibc/stdio.c b/lib/libc/picolibc/stdio.c index 342eedc877101..56df517f1d4e3 100644 --- a/lib/libc/picolibc/stdio.c +++ b/lib/libc/picolibc/stdio.c @@ -10,8 +10,7 @@ static LIBC_DATA int (*_stdout_hook)(int); int z_impl_zephyr_fputc(int a, FILE *out) { - (*_stdout_hook)(a); - return 0; + return ((out == stdout) || (out == stderr)) ? (*_stdout_hook)(a) : EOF; } #ifdef CONFIG_USERSPACE @@ -24,8 +23,7 @@ static inline int z_vrfy_zephyr_fputc(int c, FILE *stream) static int picolibc_put(char a, FILE *f) { - zephyr_fputc(a, f); - return 0; + return zephyr_fputc(a, f); } static LIBC_DATA FILE __stdout = FDEV_SETUP_STREAM(picolibc_put, NULL, NULL, 0);