|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #include <conio.h>
|
| #include <corecrt_internal_lowio.h>
|
| #include <corecrt_internal_mbstring.h>
|
| #include <corecrt_internal_stdio.h>
|
| #include <corecrt_internal_ptd_propagation.h>
|
| #include <stdlib.h>
|
|
|
|
|
|
|
| extern "C" int __cdecl _putch(int const c)
|
| {
|
| return __acrt_lock_and_call(__acrt_conio_lock, [&]
|
| {
|
| return _putch_nolock(c);
|
| });
|
| }
|
|
|
| extern "C" int __cdecl _putch_nolock_internal(int const c, __crt_cached_ptd_host& ptd)
|
| {
|
| __acrt_ptd* const raw_ptd = ptd.get_raw_ptd();
|
| unsigned char* const ch_buf = raw_ptd->_putch_buffer;
|
| unsigned short* const pch_buf_used = &raw_ptd->_putch_buffer_used;
|
|
|
|
|
|
|
| int result = c;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| if (*pch_buf_used == 1)
|
| {
|
| _ASSERTE(isleadbyte(ch_buf[0]) != 0);
|
|
|
| ch_buf[1] = static_cast<unsigned char>(c);
|
| }
|
| else
|
| {
|
| ch_buf[0] = static_cast<unsigned char>(c);
|
| }
|
|
|
| if (*pch_buf_used == 0 && isleadbyte(ch_buf[0]))
|
| {
|
|
|
| *pch_buf_used = 1;
|
| }
|
| else
|
| {
|
| wchar_t wchar;
|
| if (_mbtowc_internal(&wchar, reinterpret_cast<char const*>(ch_buf), *pch_buf_used + 1, ptd) == -1 ||
|
| _putwch_nolock(wchar) == WEOF)
|
| {
|
| result = EOF;
|
| }
|
|
|
|
|
| *pch_buf_used = 0;
|
| }
|
|
|
| return result;
|
| }
|
|
|
| extern "C" int __cdecl _putch_nolock(int const c)
|
| {
|
| __crt_cached_ptd_host ptd;
|
| return _putch_nolock_internal(c, ptd);
|
| }
|
|
|