libs/libc/wchar: add getwc implementation

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
guoshichao 2023-12-15 16:16:27 +08:00 committed by Xiang Xiao
parent 8c37c3841b
commit 0b2f7f7f3c
5 changed files with 65 additions and 2 deletions

View file

@ -150,7 +150,7 @@ wint_t fputwc_unlocked(wchar_t, FAR FILE *);
int fputws(FAR const wchar_t *, FILE *);
int fputws_unlocked(FAR const wchar_t *, FAR FILE *);
int fwide(FILE *, int);
wint_t getwc(FILE *);
wint_t getwc(FAR FILE *);
wint_t getwchar(void);
int mbsinit(FAR const mbstate_t *);
size_t mbrlen(FAR const char *, size_t, FAR mbstate_t *);

View file

@ -109,6 +109,7 @@
"gets","stdio.h","defined(CONFIG_FILE_STREAM)","FAR char *","FAR char *"
"gettext","libintl.h","defined(CONFIG_LIBC_LOCALE_GETTEXT)","FAR char *","FAR const char *"
"gettimeofday","sys/time.h","","int","FAR struct timeval *","FAR struct timezone *"
"getwc","wchar.h","defined(CONFIG_FILE_STREAM)","wint_t","FAR FILE *"
"gmtime","time.h","","FAR struct tm *","FAR const time_t *"
"gmtime_r","time.h","","FAR struct tm *","FAR const time_t *","FAR struct tm *"
"htonl","arpa/inet.h","","uint32_t","uint32_t"

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

View file

@ -106,7 +106,8 @@ if(CONFIG_FILE_STREAM)
lib_fputws.c
lib_fopencookie.c
lib_fmemopen.c
lib_fgetwc.c)
lib_fgetwc.c
lib_getwc.c)
endif()
target_sources(c PRIVATE ${SRCS})

View file

@ -49,6 +49,7 @@ CSRCS += lib_scanf.c lib_vscanf.c lib_fscanf.c lib_vfscanf.c lib_tmpfile.c
CSRCS += lib_setbuf.c lib_setvbuf.c lib_libfilelock.c lib_libgetstreams.c
CSRCS += lib_setbuffer.c lib_fputwc.c lib_putwc.c lib_fputws.c
CSRCS += lib_fopencookie.c lib_fmemopen.c lib_open_memstream.c lib_fgetwc.c
CSRCS += lib_getwc.c
endif
# Add the stdio directory to the build

View file

@ -0,0 +1,60 @@
/****************************************************************************
* libs/libc/stdio/lib_getwc.c
*
* Copyright © 2005-2014 Rich Felker, et al.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <wchar.h>
#ifdef CONFIG_FILE_STREAM
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getwc
*
* Description:
* Get wide character from stream
*
* Input Parameters:
* f - Pointer to a FILE object that identifies an input stream
*
* Returned Value:
* Return the character read is returned,
* Return WEOF is the sequence of bytes that read cannot be interpreted as
* a valid wide characted, and sets the errno to EILSEQ
*
****************************************************************************/
wint_t getwc(FAR FILE *f)
{
return fgetwc(f);
}
#endif /* CONFIG_FILE_STREAM */