From ddc6e317404c3746a600f643be0f00e45217ffd4 Mon Sep 17 00:00:00 2001 From: guoshichao Date: Thu, 25 Apr 2024 16:52:12 +0800 Subject: [PATCH] libc/fputwc: fix the return value truncated from stdio interface Signed-off-by: guoshichao --- libs/libc/stdio/lib_fputwc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/libc/stdio/lib_fputwc.c b/libs/libc/stdio/lib_fputwc.c index 5aab48bfe6..c3e3fa56f4 100644 --- a/libs/libc/stdio/lib_fputwc.c +++ b/libs/libc/stdio/lib_fputwc.c @@ -60,22 +60,27 @@ wint_t fputwc_unlocked(wchar_t c, FAR FILE *f) { char mbc[MB_LEN_MAX]; + wint_t wc; int l; if (isascii(c)) { - c = putc_unlocked(c, f); + wc = putc_unlocked(c, f); } else { l = wctomb(mbc, c); if (l < 0 || lib_fwrite_unlocked(mbc, l, f) < l) { - c = WEOF; + wc = WEOF; + } + else + { + wc = c; } } - return c; + return wc; } /**************************************************************************** @@ -97,9 +102,9 @@ wint_t fputwc_unlocked(wchar_t c, FAR FILE *f) wint_t fputwc(wchar_t c, FAR FILE *f) { flockfile(f); - c = fputwc_unlocked(c, f); + wint_t wc = fputwc_unlocked(c, f); funlockfile(f); - return c; + return wc; } #endif /* CONFIG_FILE_STREAM */