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:51 UTC
[incubator-nuttx] 04/04: libc: Implement mblen,
mbstowcs and wcstombs
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 */