You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/02 13:13:47 UTC

[incubator-nuttx] branch master updated (4fe35cc -> de50900)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 4fe35cc  boards: Remove OUTPUT_FORMAT and OUTPUT_ARCH from ld script
     new 57caa4e  libc: Move MB_LEN_MAX from lib_wctob.c to limits.h
     new f1433ee  libc: Fix the typo error in wcrtomb
     new 7cbcbcd  libc: Implement wcsrtombs, wcsnrtombs and mbsnrtowcs
     new de50900  libc: Implement mblen, mbstowcs and wcstombs

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/limits.h                                   | 10 +++++
 include/stdlib.h                                   |  3 ++
 include/wchar.h                                    |  2 +-
 libs/libc/libc.csv                                 |  9 +++-
 libs/libc/stdlib/Make.defs                         |  3 +-
 .../libc/stdlib/lib_mblen.c                        | 20 +++++----
 .../libc/stdlib/lib_mbstowcs.c                     | 22 ++++------
 libs/libc/stdlib/lib_mbtowc.c                      |  4 +-
 .../libc/stdlib/lib_wcstombs.c                     | 16 +++----
 libs/libc/wchar/Make.defs                          |  2 +-
 libs/libc/wchar/lib_mbrlen.c                       |  4 +-
 libs/libc/wchar/lib_mbsnrtowcs.c                   | 20 ++++++++-
 libs/libc/wchar/lib_mbsrtowcs.c                    |  3 +-
 libs/libc/wchar/lib_wcrtomb.c                      | 10 ++---
 libs/libc/wchar/lib_wcsnrtombs.c                   | 49 ++++++++++++++++++++--
 .../libc/wchar/lib_wcsrtombs.c                     | 25 +++++------
 libs/libc/wchar/lib_wctob.c                        | 12 +-----
 17 files changed, 144 insertions(+), 70 deletions(-)
 copy arch/risc-v/src/litex/litex_allocateheap.c => libs/libc/stdlib/lib_mblen.c (84%)
 copy mm/umm_heap/umm_mallinfo.c => libs/libc/stdlib/lib_mbstowcs.c (82%)
 copy arch/risc-v/src/litex/litex_allocateheap.c => libs/libc/stdlib/lib_wcstombs.c (85%)
 copy mm/umm_heap/umm_mallinfo.c => libs/libc/wchar/lib_wcsrtombs.c (81%)


[incubator-nuttx] 02/04: libc: Fix the typo error in wcrtomb

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit f1433ee8d20d3da01ab3ec0384896e44fc0b9f2c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 2 13:46:55 2020 +0800

    libc: Fix the typo error in wcrtomb
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: Id8841ca33a47cea3a1b68229979fd607049f766d
---
 libs/libc/wchar/lib_wcrtomb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/libc/wchar/lib_wcrtomb.c b/libs/libc/wchar/lib_wcrtomb.c
index d28c49b..cccdde0 100644
--- a/libs/libc/wchar/lib_wcrtomb.c
+++ b/libs/libc/wchar/lib_wcrtomb.c
@@ -62,7 +62,7 @@ size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t *ps)
 
   if (s == NULL)
     {
-      retval = wctomb(buf, L'\0');
+      retval = wctomb(buf, wc);
     }
   else
     {


[incubator-nuttx] 04/04: libc: Implement mblen, mbstowcs and wcstombs

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit de509004fddbff4a2aa2349589752677244a8967
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 2 13:54:30 2020 +0800

    libc: Implement mblen, mbstowcs and wcstombs
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I682c39fc132a1614b91284670882e331add765a9
---
 include/stdlib.h                |  3 +++
 libs/libc/libc.csv              |  3 +++
 libs/libc/stdlib/Make.defs      |  3 ++-
 libs/libc/stdlib/lib_mblen.c    | 47 +++++++++++++++++++++++++++++++++++++++++
 libs/libc/stdlib/lib_mbstowcs.c | 47 +++++++++++++++++++++++++++++++++++++++++
 libs/libc/stdlib/lib_wcstombs.c | 43 +++++++++++++++++++++++++++++++++++++
 6 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/include/stdlib.h b/include/stdlib.h
index b49723e..f25d7f3 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -243,8 +243,11 @@ FAR char *itoa(int val, FAR char *str, int base);
 /* Wide character operations */
 
 #ifdef CONFIG_LIBC_WCHAR
+int       mblen(FAR const char *s, size_t n);
 int       mbtowc(FAR wchar_t *pwc, FAR const char *s, size_t n);
+size_t    mbstowcs(FAR wchar_t *dst, FAR const char *src, size_t len);
 int       wctomb(FAR char *s, wchar_t wchar);
+size_t    wcstombs(FAR char *dst, FAR const wchar_t *src, size_t len);
 #endif
 
 /* Memory Management */
diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv
index f6c6cf5..f1f6375 100644
--- a/libs/libc/libc.csv
+++ b/libs/libc/libc.csv
@@ -86,10 +86,12 @@
 "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int"
 "malloc","stdlib.h","","FAR void *","size_t"
 "match","nuttx/lib/regex.h","","int","FAR const char *","FAR const char *"
+"mblen","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const char *","size_t"
 "mbrlen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const char *","size_t","FAR mbstate_t *"
 "mbrtowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char *","size_t","FAR mbstate_t *"
 "mbsnrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","size_t","FAR mbstate_t *"
 "mbsrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","FAR mbstate_t *"
+"mbstowcs","stdlib.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char *","size_t"
 "mbtowc","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR wchar_t *","FAR const char *","size_t"
 "memccpy","string.h","","FAR void *","FAR void *","FAR const void *","int","size_t"
 "memchr","string.h","","FAR void *","FAR const void *","int","size_t"
@@ -225,6 +227,7 @@
 "wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *"
 "wcsnrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","size_t","FAR mbstate_t *"
 "wcsrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","FAR mbstate_t *"
+"wcstombs","stdlib.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t *","size_t"
 "wcstod","wchar.h","defined(CONFIG_LIBC_WCHAR)","double","FAR const wchar_t *","FAR wchar_t **"
 "wcstof","wchar.h","defined(CONFIG_LIBC_WCHAR)","float","FAR const wchar_t *","FAR wchar_t **"
 "wcstol","wchar.h","defined(CONFIG_LIBC_WCHAR)","long int","FAR const wchar_t *","FAR wchar_t **","int"
diff --git a/libs/libc/stdlib/Make.defs b/libs/libc/stdlib/Make.defs
index e724bff..1fbb440 100644
--- a/libs/libc/stdlib/Make.defs
+++ b/libs/libc/stdlib/Make.defs
@@ -28,7 +28,8 @@ CSRCS += lib_strtod.c lib_strtof.c lib_strtold.c lib_checkbase.c
 CSRCS += lib_mktemp.c lib_mkstemp.c
 
 ifeq ($(CONFIG_LIBC_WCHAR),y)
-CSRCS += lib_mbtowc.c lib_wctomb.c
+CSRCS += lib_mblen.c lib_mbtowc.c lib_wctomb.c
+CSRCS += lib_mbstowcs.c lib_wcstombs.c
 endif
 
 ifeq ($(CONFIG_PSEUDOTERM_SUSV1),y)
diff --git a/libs/libc/stdlib/lib_mblen.c b/libs/libc/stdlib/lib_mblen.c
new file mode 100644
index 0000000..e5e3e17
--- /dev/null
+++ b/libs/libc/stdlib/lib_mblen.c
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * libs/libc/stdlib/lib_mblen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <wchar.h>
+
+#ifdef CONFIG_LIBC_WCHAR
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mblen
+ *
+ * Description:
+ *   Determine number of bytes in next multibyte character
+ *
+ ****************************************************************************/
+
+int mblen(FAR const char *s, size_t n)
+{
+  return mbtowc(NULL, s, n);
+}
+
+#endif
diff --git a/libs/libc/stdlib/lib_mbstowcs.c b/libs/libc/stdlib/lib_mbstowcs.c
new file mode 100644
index 0000000..2dd4201
--- /dev/null
+++ b/libs/libc/stdlib/lib_mbstowcs.c
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * libs/libc/stdlib/lib_mbstowcs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <wchar.h>
+
+#ifdef CONFIG_LIBC_WCHAR
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mbsrtowcs
+ *
+ * Description:
+ *   Convert a multibyte string to a wide-character string
+ *
+ ****************************************************************************/
+
+size_t mbstowcs(FAR wchar_t *dst, FAR const char *src, size_t len)
+{
+  return mbsrtowcs(dst, &src, len, NULL);
+}
+
+#endif
diff --git a/libs/libc/stdlib/lib_wcstombs.c b/libs/libc/stdlib/lib_wcstombs.c
new file mode 100644
index 0000000..e1560b8
--- /dev/null
+++ b/libs/libc/stdlib/lib_wcstombs.c
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/stdlib/lib_wcstombs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <wchar.h>
+
+#ifdef CONFIG_LIBC_WCHAR
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: wcstombs
+ ****************************************************************************/
+
+size_t wcstombs(FAR char *dst, FAR const wchar_t *src, size_t len)
+{
+  return wcsrtombs(dst, &src, len, NULL);
+}
+
+#endif /* CONFIG_LIBC_WCHAR */


[incubator-nuttx] 03/04: libc: Implement wcsrtombs, wcsnrtombs and mbsnrtowcs

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 7cbcbcde51052fc854c6feac0a96558cb70613fa
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 2 12:22:26 2020 +0800

    libc: Implement wcsrtombs, wcsnrtombs and mbsnrtowcs
    
    and update the related stuff in libs/libc/libc.csv
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: Id695a7f07bf18a7b4e526297f9131c75ddb79d30
---
 include/wchar.h                  |  2 +-
 libs/libc/libc.csv               |  6 ++++-
 libs/libc/stdlib/lib_mbtowc.c    |  4 ++--
 libs/libc/wchar/Make.defs        |  2 +-
 libs/libc/wchar/lib_mbrlen.c     |  4 ++--
 libs/libc/wchar/lib_mbsnrtowcs.c | 20 +++++++++++++++-
 libs/libc/wchar/lib_mbsrtowcs.c  |  3 ++-
 libs/libc/wchar/lib_wcsnrtombs.c | 49 +++++++++++++++++++++++++++++++++++++---
 libs/libc/wchar/lib_wcsrtombs.c  | 46 +++++++++++++++++++++++++++++++++++++
 9 files changed, 124 insertions(+), 12 deletions(-)

diff --git a/include/wchar.h b/include/wchar.h
index 6b7ba0d..d5719b2 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -168,7 +168,7 @@ size_t            mbrtowc(FAR wchar_t *, FAR const char *, size_t,
                       FAR mbstate_t *);
 size_t            mbsnrtowcs(FAR wchar_t *, FAR const char **, size_t,
                       size_t, FAR mbstate_t *);
-size_t            mbsrtowcs(wchar_t *, FAR const char **, size_t,
+size_t            mbsrtowcs(FAR wchar_t *, FAR const char **, size_t,
                       FAR mbstate_t *);
 wint_t            putwc(wchar_t, FILE *);
 wint_t            putwchar(wchar_t);
diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv
index ce2b716..f6c6cf5 100644
--- a/libs/libc/libc.csv
+++ b/libs/libc/libc.csv
@@ -17,6 +17,7 @@
 "b16sin","fixedmath.h","","b16_t","b16_t"
 "b16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t"
 "basename","libgen.h","","FAR char *","FAR char *"
+"btowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","int"
 "cfgetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *"
 "cfsetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t"
 "chdir","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
@@ -85,9 +86,11 @@
 "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int"
 "malloc","stdlib.h","","FAR void *","size_t"
 "match","nuttx/lib/regex.h","","int","FAR const char *","FAR const char *"
+"mbrlen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const char *","size_t","FAR mbstate_t *"
 "mbrtowc","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char *","size_t","FAR mbstate_t *"
 "mbsnrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","size_t","FAR mbstate_t *"
-"mbtowc","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR wchar_t *","FAR const wchar_t *","size_t"
+"mbsrtowcs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const char **","size_t","FAR mbstate_t *"
+"mbtowc","stdlib.h","defined(CONFIG_LIBC_WCHAR)","int","FAR wchar_t *","FAR const char *","size_t"
 "memccpy","string.h","","FAR void *","FAR void *","FAR const void *","int","size_t"
 "memchr","string.h","","FAR void *","FAR const void *","int","size_t"
 "memcmp","string.h","","int","FAR const void *","FAR const void *","size_t"
@@ -221,6 +224,7 @@
 "wcslcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","FAR const wchar_t *","size_t"
 "wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *"
 "wcsnrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","size_t","FAR mbstate_t *"
+"wcsrtombs","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","FAR const wchar_t **","size_t","FAR mbstate_t *"
 "wcstod","wchar.h","defined(CONFIG_LIBC_WCHAR)","double","FAR const wchar_t *","FAR wchar_t **"
 "wcstof","wchar.h","defined(CONFIG_LIBC_WCHAR)","float","FAR const wchar_t *","FAR wchar_t **"
 "wcstol","wchar.h","defined(CONFIG_LIBC_WCHAR)","long int","FAR const wchar_t *","FAR wchar_t **","int"
diff --git a/libs/libc/stdlib/lib_mbtowc.c b/libs/libc/stdlib/lib_mbtowc.c
index 159af2a..abe0f8d 100644
--- a/libs/libc/stdlib/lib_mbtowc.c
+++ b/libs/libc/stdlib/lib_mbtowc.c
@@ -50,7 +50,7 @@
  *
  ****************************************************************************/
 
-int mbtowc(FAR wchar_t * pwc, FAR const char *s, size_t n)
+int mbtowc(FAR wchar_t *pwc, FAR const char *s, size_t n)
 {
   if (s == NULL)
     {
@@ -64,7 +64,7 @@ int mbtowc(FAR wchar_t * pwc, FAR const char *s, size_t n)
 
   if (pwc)
     {
-      *pwc = (wchar_t) * s;
+      *pwc = (wchar_t)*s;
     }
 
   return (*s != '\0');
diff --git a/libs/libc/wchar/Make.defs b/libs/libc/wchar/Make.defs
index f975ca2..f9a80fc 100644
--- a/libs/libc/wchar/Make.defs
+++ b/libs/libc/wchar/Make.defs
@@ -43,7 +43,7 @@ CSRCS += lib_wcslcpy.c lib_wcsxfrm.c lib_wcrtomb.c lib_wcsftime.c
 CSRCS += lib_wcscoll.c lib_wcstol.c lib_wcstoll.c lib_wcstoul.c
 CSRCS += lib_wcstoull.c lib_wcstold.c lib_wcstof.c lib_wcstod.c
 CSRCS += lib_swprintf.c lib_mbsnrtowcs.c lib_wcsnrtombs.c
-CSRCS += lib_mbrlen.c lib_mbsrtowcs.c
+CSRCS += lib_mbrlen.c lib_mbsrtowcs.c lib_wcsrtombs.c
 
 # Add the wchar directory to the build
 
diff --git a/libs/libc/wchar/lib_mbrlen.c b/libs/libc/wchar/lib_mbrlen.c
index 44e077f..fd6b897 100644
--- a/libs/libc/wchar/lib_mbrlen.c
+++ b/libs/libc/wchar/lib_mbrlen.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * libs/libc/wchar/lib_mbrtowc.c
+ * libs/libc/wchar/lib_mbrlen.c
  *
  *   Copyright (c) 2002-2004 Tim J. Robbins.
  *   All rights reserved.
@@ -60,7 +60,7 @@
  *
  ****************************************************************************/
 
-size_t mbrlen(const char *s, size_t n, mbstate_t *ps)
+size_t mbrlen(FAR const char *s, size_t n, FAR mbstate_t *ps)
 {
   return mbrtowc(NULL, s, n, ps);
 }
diff --git a/libs/libc/wchar/lib_mbsnrtowcs.c b/libs/libc/wchar/lib_mbsnrtowcs.c
index 6df037a..4bd5ecf 100644
--- a/libs/libc/wchar/lib_mbsnrtowcs.c
+++ b/libs/libc/wchar/lib_mbsnrtowcs.c
@@ -84,7 +84,25 @@
 size_t mbsnrtowcs(FAR wchar_t *dst, FAR const char **src, size_t nms,
                   size_t len, FAR mbstate_t *ps)
 {
-  return len;
+  size_t i;
+
+  if (dst == NULL)
+    {
+      return strnlen(*src, nms);
+    }
+
+  for (i = 0; i < nms && i < len; i++)
+    {
+      dst[i] = (wchar_t)(*src)[i];
+      if (dst[i] == L'\0')
+        {
+          *src = NULL;
+          return i;
+        }
+    }
+
+  *src += i;
+  return i;
 }
 
 #endif /* CONFIG_LIBC_WCHAR */
diff --git a/libs/libc/wchar/lib_mbsrtowcs.c b/libs/libc/wchar/lib_mbsrtowcs.c
index 7cabfdd..e80d53a 100644
--- a/libs/libc/wchar/lib_mbsrtowcs.c
+++ b/libs/libc/wchar/lib_mbsrtowcs.c
@@ -61,7 +61,8 @@
  *
  ****************************************************************************/
 
-size_t mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps)
+size_t mbsrtowcs(FAR wchar_t *dst, FAR const char **src,
+                 size_t len, FAR mbstate_t *ps)
 {
   return mbsnrtowcs(dst, src, SIZE_MAX, len, ps);
 }
diff --git a/libs/libc/wchar/lib_wcsnrtombs.c b/libs/libc/wchar/lib_wcsnrtombs.c
index 0464af0..9143f1c 100644
--- a/libs/libc/wchar/lib_wcsnrtombs.c
+++ b/libs/libc/wchar/lib_wcsnrtombs.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * libs/libc/stdio/lib_asprintf.c
+ * libs/libc/wchar/lib_wcsnrtombs.c
  *
  *   Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
@@ -85,9 +85,52 @@
  ****************************************************************************/
 
 size_t wcsnrtombs(FAR char *dst, FAR const wchar_t **src, size_t nwc,
-                  size_t len, mbstate_t *ps)
+                  size_t len, FAR mbstate_t *ps)
 {
-  return len;
+  size_t i;
+
+  if (dst == NULL)
+    {
+      for (i = 0; i < nwc; i++)
+        {
+          wchar_t wc = (*src)[i];
+
+          if (wc < 0 || wc > 0xff)
+            {
+              set_errno(EILSEQ);
+              return -1;
+            }
+
+          if (wc == L'\0')
+            {
+              return i;
+            }
+        }
+
+      return i;
+    }
+
+  for (i = 0; i < nwc && i < len; i++)
+    {
+      wchar_t wc = (*src)[i];
+
+      if (wc < 0 || wc > 0xff)
+        {
+          *src += i;
+          set_errno(EILSEQ);
+          return -1;
+        }
+
+      dst[i] = wc;
+      if (wc == L'\0')
+        {
+          *src = NULL;
+          return i;
+        }
+    }
+
+  *src += i;
+  return i;
 }
 
 #endif /* CONFIG_LIBC_WCHAR */
diff --git a/libs/libc/wchar/lib_wcsrtombs.c b/libs/libc/wchar/lib_wcsrtombs.c
new file mode 100644
index 0000000..dc6b651
--- /dev/null
+++ b/libs/libc/wchar/lib_wcsrtombs.c
@@ -0,0 +1,46 @@
+/****************************************************************************
+ * libs/libc/wchar/lib_wcsrtombs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <wchar.h>
+
+#ifdef CONFIG_LIBC_WCHAR
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: wcsrtombs
+ *
+ * Description:
+ *   Convert a wide-characterto a  multibyte string string
+ ****************************************************************************/
+
+size_t wcsrtombs(FAR char *dst, FAR const wchar_t **src,
+                 size_t len, FAR mbstate_t *ps)
+{
+  return wcsnrtombs(dst, src, SIZE_MAX, len, ps);
+}
+
+#endif /* CONFIG_LIBC_WCHAR */


[incubator-nuttx] 01/04: libc: Move MB_LEN_MAX from lib_wctob.c to limits.h

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 57caa4e12121fa4af736f172c03dd09c6223c671
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 2 12:03:59 2020 +0800

    libc: Move MB_LEN_MAX from lib_wctob.c to limits.h
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I3a5addac99adb02f57aba05aa9fe2e6aaf31071d
---
 include/limits.h              | 10 ++++++++++
 libs/libc/wchar/lib_wcrtomb.c | 10 +++++-----
 libs/libc/wchar/lib_wctob.c   | 12 ++----------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/limits.h b/include/limits.h
index 88c70cc..752a587 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -49,7 +49,9 @@
 /********************************************************************************
  * Pre-processor Definitions
  ********************************************************************************/
+
 /* Default values for user configurable limits **********************************/
+
 /* Maximum number of bytes in a filename (not including terminating null). */
 
 #ifndef CONFIG_NAME_MAX
@@ -68,6 +70,13 @@
 #  endif
 #endif
 
+/* Maximum length of any multibyte character in any locale.
+ * We define this value here since the gcc header does not define
+ * the correct value.
+ */
+
+#define MB_LEN_MAX            1
+
 /* Configurable limits required by POSIX ****************************************
  *
  * Required for all implementations:
@@ -303,6 +312,7 @@
 #define SEM_VALUE_MAX  _POSIX_SEM_VALUE_MAX
 
 /* Required for readv() and writev() */
+
 /* There really is no upper limit on the number of vectors */
 
 #define IOV_MAX        INT_MAX
diff --git a/libs/libc/wchar/lib_wcrtomb.c b/libs/libc/wchar/lib_wcrtomb.c
index c514a62..d28c49b 100644
--- a/libs/libc/wchar/lib_wcrtomb.c
+++ b/libs/libc/wchar/lib_wcrtomb.c
@@ -55,14 +55,14 @@
  *
  ****************************************************************************/
 
-size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t * ps)
+size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t *ps)
 {
   int retval = 0;
-  char buf[10];
+  char buf[MB_LEN_MAX];
 
   if (s == NULL)
     {
-      retval = wctomb((char *)buf, L'\0');
+      retval = wctomb(buf, L'\0');
     }
   else
     {
@@ -71,11 +71,11 @@ size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t * ps)
 
   if (retval == -1)
     {
-      return (size_t) (-1);
+      return (size_t)(-1);
     }
   else
     {
-      return (size_t) retval;
+      return (size_t)retval;
     }
 }
 #endif
diff --git a/libs/libc/wchar/lib_wctob.c b/libs/libc/wchar/lib_wctob.c
index d1079a0..5329ff8 100644
--- a/libs/libc/wchar/lib_wctob.c
+++ b/libs/libc/wchar/lib_wctob.c
@@ -45,26 +45,18 @@
 #ifdef CONFIG_LIBC_WCHAR
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#ifndef MB_LEN_MAX
-#  define MB_LEN_MAX 8
-#endif
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 int wctob(wint_t wc)
 {
-  unsigned char pmb[MB_LEN_MAX];
+  char pmb[MB_LEN_MAX];
 
   if (wc == WEOF)
     {
       return EOF;
     }
 
-  return wctomb((char *)pmb, wc) == 1 ? (int)pmb[0] : EOF;
+  return wctomb(pmb, wc) == 1 ? (int)pmb[0] : EOF;
 }
 #endif