Skip to content

Commit d67090c

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

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

include/wchar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ size_t mbsnrtowcs(FAR wchar_t *, FAR const char **, size_t,
159159
size_t mbsrtowcs(FAR wchar_t *, FAR const char **, size_t,
160160
FAR mbstate_t *);
161161
wint_t putwc(wchar_t, FILE *);
162+
wint_t putwc_unlocked(wchar_t, FAR FILE *);
162163
wint_t putwchar(wchar_t);
163164
int swprintf(FAR wchar_t *, size_t, FAR const wchar_t *, ...);
164165
int swscanf(FAR const wchar_t *, FAR const wchar_t *, ...);

libs/libc/stdio/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ if(CONFIG_FILE_STREAM)
102102
lib_libstream.c
103103
lib_libfilelock.c
104104
lib_libgetstreams.c
105-
lib_fputwc.c)
105+
lib_fputwc.c
106+
lib_putwc.c)
106107
endif()
107108

108109
target_sources(c PRIVATE ${SRCS})

libs/libc/stdio/Make.defs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CSRCS += lib_fputs.c lib_ungetc.c lib_fprintf.c lib_vfprintf.c
4747
CSRCS += lib_feof.c lib_ferror.c lib_rewind.c lib_clearerr.c
4848
CSRCS += lib_scanf.c lib_vscanf.c lib_fscanf.c lib_vfscanf.c lib_tmpfile.c
4949
CSRCS += lib_setbuf.c lib_setvbuf.c lib_libstream.c lib_libfilelock.c
50-
CSRCS += lib_libgetstreams.c lib_setbuffer.c lib_fputwc.c
50+
CSRCS += lib_libgetstreams.c lib_setbuffer.c lib_fputwc.c lib_putwc.c
5151
endif
5252

5353
# Add the stdio directory to the build

libs/libc/stdio/lib_putwc.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/****************************************************************************
2+
* libs/libc/stdio/lib_putwc.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 <wchar.h>
32+
#include <stdio.h>
33+
34+
#ifdef CONFIG_FILE_STREAM
35+
36+
/****************************************************************************
37+
* Public Functions
38+
****************************************************************************/
39+
40+
/****************************************************************************
41+
* Name: putwc_unlocked
42+
*
43+
* Description:
44+
* Write wide character to stream without lock the stream
45+
*
46+
* Input Parameters:
47+
* c - the wide character to write
48+
* f - the FILE object that identifies an output stream
49+
*
50+
* Returned Value:
51+
* Return the wide character that written in to the stream on success,
52+
* return WEOF on fail write to the stream
53+
*
54+
****************************************************************************/
55+
56+
wint_t putwc_unlocked(wchar_t c, FAR FILE *f)
57+
{
58+
return fputwc_unlocked(c, f);
59+
}
60+
61+
/****************************************************************************
62+
* Name: putwc
63+
*
64+
* Description:
65+
* Write wide character to stream
66+
*
67+
* Input Parameters:
68+
* c - the wide character to write
69+
* f - the FILE object that identifies an output stream
70+
*
71+
* Returned Value:
72+
* Return the wide character that written in to the stream on success,
73+
* return WEOF on fail write to the stream
74+
*
75+
****************************************************************************/
76+
77+
wint_t putwc(wchar_t c, FAR FILE *f)
78+
{
79+
flockfile(f);
80+
c = putwc_unlocked(c, f);
81+
funlockfile(f);
82+
return c;
83+
}
84+
85+
#endif /* CONFIG_FILE_STREAM */

0 commit comments

Comments
 (0)