libc: Implement mblen, mbstowcs and wcstombs

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I682c39fc132a1614b91284670882e331add765a9
This commit is contained in:
Xiang Xiao 2020-06-02 13:54:30 +08:00 committed by patacongo
parent 7cbcbcde51
commit de509004fd
6 changed files with 145 additions and 1 deletions

View File

@ -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 */

View File

@ -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"

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 */