xref: /reactos/sdk/lib/ucrt/conio/putwch.cpp (revision 04e0dc4a)
1 //
2 // putwch.cpp
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // Defines _putwch(), which writes a wide character to the console.
7 //
8 #include <conio.h>
9 #include <corecrt_internal_lowio.h>
10 #include <corecrt_internal_ptd_propagation.h>
11 
12 // Writes a wide character to the console.  Returns the character on success,
13 // WEOF on failure.
_putwch(wchar_t const c)14 extern "C" wint_t __cdecl _putwch(wchar_t const c)
15 {
16     return __acrt_lock_and_call(__acrt_conio_lock, [&]
17     {
18         return _putwch_nolock(c);
19     });
20 }
21 
_putwch_nolock(wchar_t const c)22 extern "C" wint_t __cdecl _putwch_nolock(wchar_t const c)
23 {
24     if (__dcrt_lowio_ensure_console_output_initialized() == FALSE)
25         return WEOF;
26 
27     // Write character to console:
28     DWORD charsWritten;
29     if (__dcrt_write_console(&c, 1, &charsWritten) == FALSE)
30         return WEOF;
31 
32     return c;
33 }
34 
_putwch_nolock_internal(wchar_t const c,__crt_cached_ptd_host &)35 extern "C" wint_t __cdecl _putwch_nolock_internal(wchar_t const c, __crt_cached_ptd_host&)
36 {
37     // Currently _putwch_nolock does not require any PTD access. Do not need to propagate __crt_cached_ptd_host&.
38     return _putwch_nolock(c);
39 }
40