Skip to content

Commit 357a405

Browse files
committed
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 <ycsin@meta.com>
1 parent af57038 commit 357a405

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/libc/picolibc/libc-hooks.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static LIBC_DATA int (*_stdout_hook)(int);
3030

3131
int z_impl_zephyr_fputc(int a, FILE *out)
3232
{
33-
(*_stdout_hook)(a);
34-
return 0;
33+
return ((out == stdout) || (out == stderr)) ? (*_stdout_hook)(a) : EOF;
3534
}
3635

3736
#ifdef CONFIG_USERSPACE
@@ -44,8 +43,7 @@ static inline int z_vrfy_zephyr_fputc(int c, FILE *stream)
4443

4544
static int picolibc_put(char a, FILE *f)
4645
{
47-
zephyr_fputc(a, f);
48-
return 0;
46+
return zephyr_fputc(a, f);
4947
}
5048

5149
static LIBC_DATA FILE __stdout = FDEV_SETUP_STREAM(picolibc_put, NULL, NULL, 0);

0 commit comments

Comments
 (0)