libc: Implement wcsrtombs, wcsnrtombs and mbsnrtowcs
and update the related stuff in libs/libc/libc.csv Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: Id695a7f07bf18a7b4e526297f9131c75ddb79d30
This commit is contained in:
parent
f1433ee8d2
commit
7cbcbcde51
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 <gnutt@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 */
|
||||
|
|
|
@ -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 */
|
Loading…
Reference in New Issue