diff --git a/include/wchar.h b/include/wchar.h index 0644cb9f40f..4c0e42197bd 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -180,8 +180,10 @@ int mbsinit(FAR const mbstate_t *); size_t mbrlen(FAR const char *, size_t, FAR mbstate_t *); size_t mbrtowc(wchar_t *, FAR const char *, size_t, 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, - mbstate_t *); + FAR mbstate_t *); wint_t putwc(wchar_t, FILE *); wint_t putwchar(wchar_t); int swprintf(FAR wchar_t *, size_t, FAR const wchar_t *, ...); @@ -208,6 +210,8 @@ size_t wcslcat(FAR wchar_t *, FAR const wchar_t *, size_t); FAR wchar_t *wcsncat(FAR wchar_t *, FAR const wchar_t *, size_t); int wcsncmp(FAR const wchar_t *, FAR const wchar_t *, size_t); FAR wchar_t *wcsncpy(FAR wchar_t *, FAR const wchar_t *, size_t); +size_t wcsnrtombs(FAR char *, FAR const wchar_t **, size_t, + size_t, FAR mbstate_t *); FAR wchar_t *wcspbrk(FAR const wchar_t *, FAR const wchar_t *); FAR wchar_t *wcsrchr(FAR const wchar_t *, wchar_t); size_t wcsrtombs(FAR char *, FAR const wchar_t **, size_t, diff --git a/libc/libc.csv b/libc/libc.csv index cbc0976ea11..d38cc8b161c 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -80,6 +80,7 @@ "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" "match","nuttx/lib/regex.h","","int","FAR const char *","FAR const char *" "mbrtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const char *","size_t","mbstate_t *" +"mbsnrtowcs,"wchar.h","","size_t","FAR wchar_t *","FAR const char **","size_t","size_t","mbstate_t *" "mbtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","FAR const wchar_t *","size_t" "memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" "memchr","string.h","","FAR void","FAR const void *","int c","size_t" @@ -203,6 +204,7 @@ "wcsftime","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR wchar_t *","size_t","FAR const wchar_t *","FAR const struct tm *" "wcslcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *","FAR const wchar_t *","size_t" "wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *" +"wcsnrtombs","wchar.h","","size_t","FAR char *","FAR const wchar_t **","size_t","size_t","mbstate_t *" "wcstod","wchar.h","defined(CONFIG_LIBC_WCHAR)","","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/libc/wchar/Make.defs b/libc/wchar/Make.defs index 91403cc8a22..d3a712e3de7 100644 --- a/libc/wchar/Make.defs +++ b/libc/wchar/Make.defs @@ -37,12 +37,12 @@ ifeq ($(CONFIG_LIBC_WCHAR),y) # Add the internal C files to the build -CSRCS += lib_wcscmp.c lib_wcslen.c lib_wmemchr.c lib_wmemcmp.c -CSRCS += lib_wmemcpy.c lib_wmemmove.c lib_wmemset.c lib_btowc.c -CSRCS += lib_mbrtowc.c lib_wctob.c lib_wcslcpy.c lib_wcsxfrm.c -CSRCS += lib_wcrtomb.c lib_wcsftime.c lib_wcscoll.c lib_wcstol.c -CSRCS += lib_wcstoll.c lib_wcstoul.c lib_wcstold.c lib_wcstof.c -CSRCS += lib_wcstod.c lib_swprintf.c +CSRCS += lib_wcscmp.c lib_wcslen.c lib_wmemchr.c lib_wmemcmp.c lib_wmemcpy.c +CSRCS += lib_wmemmove.c lib_wmemset.c lib_btowc.c lib_mbrtowc.c lib_wctob.c +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 lib_wcstold.c +CSRCS += lib_wcstof.c lib_wcstod.c lib_swprintf.c lib_mbsnrtowcs.c +CSRCS += lib_wcsnrtombs.c # Add the wchar directory to the build diff --git a/libc/wchar/lib_mbsnrtowcs.c b/libc/wchar/lib_mbsnrtowcs.c new file mode 100644 index 00000000000..cc60ebb6c9c --- /dev/null +++ b/libc/wchar/lib_mbsnrtowcs.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * libc/wchar/lib_mbsnrtowcs.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mbsnrtowcs + * + * Description: + * The 'mbsrtowcs' function converts a sequence of multibyte characters + * pointed to indirectly by 'src' into a sequence of corresponding wide + * characters and stores at most 'len' of them in the wchar_t array pointed + * to by 'dst', until it encounters a terminating null character ('\0'). + * + * If 'dst' is NULL, no characters are stored. + * + * If 'dst' is not NULL, the pointer pointed to by 'src' is updated to + * point to the character after the one that conversion stopped at. If + * conversion stops because a null character is encountered, *'src' is set + * to NULL. + * + * The mbstate_t argument, 'ps', is used to keep track of the shift state. + * If it is NULL, 'mbsrtowcs' uses an internal, static mbstate_t object, + * which is initialized to the initial conversion state at program startup. + * + * The 'mbsnrtowcs' function behaves identically to 'mbsrtowcs', except + * that conversion stops after reading at most 'nms' bytes from the buffer + * pointed to by 'src'. + * + * Returned Value: + * The 'mbsrtowcs' and 'mbsnrtowcs' functions return the number of wide + * characters stored in the array pointed to by 'dst' if successful, + * otherwise it returns (size_t)-1. + * + * Portability: + * 'mbsrtowcs' is defined by the C99 standard. + * 'mbsnrtowcs' is defined by the POSIX.1-2008 standard. + * + ****************************************************************************/ + +size_t mbsnrtowcs(FAR wchar_t *dst, FAR const char **src, size_t nms, + size_t len, FAR mbstate_t *ps) +{ + return len; +} + +#endif /* CONFIG_LIBC_WCHAR */ + diff --git a/libc/wchar/lib_swprintf.c b/libc/wchar/lib_swprintf.c index f108f31fac4..610c816af57 100644 --- a/libc/wchar/lib_swprintf.c +++ b/libc/wchar/lib_swprintf.c @@ -47,6 +47,8 @@ #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -75,3 +77,5 @@ int swprintf(FAR wchar_t *buf, size_t maxlen, FAR const wchar_t *fmt, ...) return n; } + +#endif /* CONFIG_LIBC_WCHAR */ diff --git a/libc/wchar/lib_wcscoll.c b/libc/wchar/lib_wcscoll.c index 54308a71176..f0b543ff142 100644 --- a/libc/wchar/lib_wcscoll.c +++ b/libc/wchar/lib_wcscoll.c @@ -61,4 +61,5 @@ int wcscoll(FAR const wchar_t *a, FAR const wchar_t *b) { return wcscmp(a, b); } -#endif + +#endif /* CONFIG_LIBC_WCHAR */ diff --git a/libc/wchar/lib_wcsnrtombs.c b/libc/wchar/lib_wcsnrtombs.c new file mode 100644 index 00000000000..a77cdc685f3 --- /dev/null +++ b/libc/wchar/lib_wcsnrtombs.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/stdio/lib_asprintf.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: + * + * Description: + * The 'wcsrtombs' function converts a string of wide characters + * indirectly pointed to by 'src' to a corresponding multibyte character + * string stored in the array pointed to by 'dst'. No more than 'len' + * bytes are written to'dst'. + * + * If 'dst' is NULL, no characters are stored. + * + * If 'dst' is not NULL, the pointer pointed to by 'src' is updated to + * point to the character after the one that conversion stopped at. If + * conversion stops because a null character is encountered, *'src' is set + * to NULL. + * + * The mbstate_t argument, 'ps', is used to keep track of the shift state. + * If it is NULL, 'wcsrtombs' uses an internal, static mbstate_t object, + * which is initialized to the initial conversion state at program startup. + * + * The 'wcsnrtombs' function behaves identically to 'wcsrtombs', except + * that conversion stops after reading at most 'nwc' characters from the + * buffer pointed to by 'src'. + * + * Returned Value: + * The 'wcsrtombs' and 'wcsnrtombs' functions return the number of bytes + * stored in the array pointed to by 'dst' (not including any terminating + * null), if successful, otherwise it returns (size_t)-1. + * + * Portability: + * 'wcsrtombs' is defined by C99 standard. + * 'wcsnrtombs' is defined by the POSIX.1-2008 standard. + ****************************************************************************/ + +size_t wcsnrtombs(FAR char *dst, FAR const wchar_t **src, size_t nwc, + size_t len, mbstate_t *ps) +{ + return len; +} + +#endif /* CONFIG_LIBC_WCHAR */