You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/06/03 19:25:58 UTC
[incubator-nuttx] 04/04: libc/wchar: Call mbsnrtowcs in mbrtowc to handle the partial sequence correctly
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit c19d37adf0bf156fdea7b18bf068e3aea3a1374f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jun 1 01:14:56 2022 +0800
libc/wchar: Call mbsnrtowcs in mbrtowc to handle the partial sequence correctly
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/wchar/lib_mbrtowc.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libs/libc/wchar/lib_mbrtowc.c b/libs/libc/wchar/lib_mbrtowc.c
index 8acf296b62..25862fce05 100644
--- a/libs/libc/wchar/lib_mbrtowc.c
+++ b/libs/libc/wchar/lib_mbrtowc.c
@@ -57,15 +57,19 @@
size_t mbrtowc(FAR wchar_t *pwc, FAR const char *s,
size_t n, FAR mbstate_t *ps)
{
- int retval = 0;
+ FAR const char *e = s;
+ size_t retval = 0;
if (s == NULL)
{
- retval = mbtowc(NULL, "", 1);
+ s = e = "";
+ n = 1;
}
- else
+
+ retval = mbsnrtowcs(pwc, &e, 1, n, ps);
+ if (retval == 1)
{
- retval = mbtowc(pwc, s, n);
+ retval = e - s;
}
return retval;