Skip to content

Commit a9b2857

Browse files
extinguishxiaoxiang781216
authored andcommitted
libs/libc/wchar: add putwchar implementation
Signed-off-by: guoshichao <[email protected]>
1 parent f8b5f61 commit a9b2857

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

libs/libc/stdio/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ set(SRCS
4444
lib_remove.c
4545
lib_tempnam.c
4646
lib_tmpnam.c
47-
lib_ultoa_invert.c)
47+
lib_ultoa_invert.c
48+
lib_putwchar.c)
4849

4950
if(CONFIG_LIBC_FLOATINGPOINT)
5051
list(APPEND SRCS lib_dtoa_engine.c lib_dtoa_data.c)

libs/libc/stdio/Make.defs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CSRCS += lib_perror.c lib_putchar.c lib_getchar.c lib_puts.c
2828
CSRCS += lib_gets_s.c lib_gets.c lib_libdgets.c
2929
CSRCS += lib_sscanf.c lib_vsscanf.c lib_libvscanf.c lib_libvsprintf.c
3030
CSRCS += lib_remove.c lib_tempnam.c lib_tmpnam.c lib_ultoa_invert.c
31-
CSRCS += lib_renameat.c
31+
CSRCS += lib_renameat.c lib_putwchar.c
3232

3333
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
3434
CSRCS += lib_dtoa_engine.c lib_dtoa_data.c

libs/libc/stdio/lib_putwchar.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/****************************************************************************
2+
* libs/libc/stdio/lib_putwchar.c
3+
*
4+
* Copyright © 2005-2014 Rich Felker, et al.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*
25+
****************************************************************************/
26+
27+
/****************************************************************************
28+
* Included Files
29+
****************************************************************************/
30+
31+
#include <limits.h>
32+
#include <stdio.h>
33+
#include <wchar.h>
34+
35+
/****************************************************************************
36+
* Public Functions
37+
****************************************************************************/
38+
39+
/****************************************************************************
40+
* Name: putwchar
41+
*
42+
* Description:
43+
* Write wide character to stdout
44+
*
45+
* Input Parameters:
46+
* c - the wide character to write
47+
*
48+
* Returned Value:
49+
* Return the wide character that written in to the stdout on success,
50+
* return WEOF on fail write to the stdout
51+
*
52+
****************************************************************************/
53+
54+
wint_t putwchar(wchar_t c)
55+
{
56+
#ifdef CONFIG_FILE_STREAM
57+
return fputwc(c, stdout);
58+
#else
59+
char mbc[MB_LEN_MAX];
60+
int l;
61+
l = wctomb(mbc, c);
62+
if (l < 0)
63+
{
64+
return WEOF;
65+
}
66+
67+
return write(STDOUT_FILENO, mbc, l) == l ? c : WEOF;
68+
#endif
69+
}

0 commit comments

Comments
 (0)