libs/libc/wchar: add putwchar implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
parent
f8b5f613e2
commit
a9b2857754
|
@ -44,7 +44,8 @@ set(SRCS
|
|||
lib_remove.c
|
||||
lib_tempnam.c
|
||||
lib_tmpnam.c
|
||||
lib_ultoa_invert.c)
|
||||
lib_ultoa_invert.c
|
||||
lib_putwchar.c)
|
||||
|
||||
if(CONFIG_LIBC_FLOATINGPOINT)
|
||||
list(APPEND SRCS lib_dtoa_engine.c lib_dtoa_data.c)
|
||||
|
|
|
@ -28,7 +28,7 @@ CSRCS += lib_perror.c lib_putchar.c lib_getchar.c lib_puts.c
|
|||
CSRCS += lib_gets_s.c lib_gets.c lib_libdgets.c
|
||||
CSRCS += lib_sscanf.c lib_vsscanf.c lib_libvscanf.c lib_libvsprintf.c
|
||||
CSRCS += lib_remove.c lib_tempnam.c lib_tmpnam.c lib_ultoa_invert.c
|
||||
CSRCS += lib_renameat.c
|
||||
CSRCS += lib_renameat.c lib_putwchar.c
|
||||
|
||||
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
|
||||
CSRCS += lib_dtoa_engine.c lib_dtoa_data.c
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/stdio/lib_putwchar.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 <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: putwchar
|
||||
*
|
||||
* Description:
|
||||
* Write wide character to stdout
|
||||
*
|
||||
* Input Parameters:
|
||||
* c - the wide character to write
|
||||
*
|
||||
* Returned Value:
|
||||
* Return the wide character that written in to the stdout on success,
|
||||
* return WEOF on fail write to the stdout
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
wint_t putwchar(wchar_t c)
|
||||
{
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
return fputwc(c, stdout);
|
||||
#else
|
||||
char mbc[MB_LEN_MAX];
|
||||
int l;
|
||||
l = wctomb(mbc, c);
|
||||
if (l < 0)
|
||||
{
|
||||
return WEOF;
|
||||
}
|
||||
|
||||
return write(STDOUT_FILENO, mbc, l) == l ? c : WEOF;
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue