Skip to content

Commit

Permalink
libs/libc/wchar: add getwc implementation
Browse files Browse the repository at this point in the history
Signed-off-by: guoshichao <[email protected]>
  • Loading branch information
guoshichao committed Dec 17, 2023
1 parent d508a2e commit e4799e2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/wchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
1 change: 1 addition & 0 deletions libs/libc/libc.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion libs/libc/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
1 change: 1 addition & 0 deletions libs/libc/stdio/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions libs/libc/stdio/lib_getwc.c
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit e4799e2

Please sign in to comment.