60 ptd.get_doserrno().set(0);
61 _ASSERTE((
"Invalid file descriptor. File possibly closed by a different thread",0));
77 __crt_cached_ptd_host
ptd;
99 bool const is_c_locale =
ptd.get_locale()->locinfo->locale_name[
LC_CTYPE] ==
nullptr;
122 __crt_cached_ptd_host&
ptd
131 write_result
result = { 0 };
135 char const c = *source_it;
145 wchar_t wc[2] = { 0 };
150 const int mb_buf_size =
sizeof(
_mbBuffer(fh));
152 for (mb_buf_used = 0; mb_buf_used < mb_buf_size &&
_mbBuffer(fh)[mb_buf_used]; ++mb_buf_used)
158 _ASSERTE(1 < mb_len && mb_buf_used < mb_len);
159 const int remaining_bytes = mb_len - mb_buf_used;
160 if (remaining_bytes <= (
buffer_end - source_it))
165 for (
int i = 0;
i < mb_buf_used; ++
i)
169 for (
int i = 0;
i < remaining_bytes; ++
i)
171 mb_buffer[
i + mb_buf_used] = source_it[
i];
175 for (
int i = 0;
i < mb_buf_used; ++
i)
181 const char*
str = mb_buffer;
190 source_it += (remaining_bytes - 1);
195 const auto bytes_to_add =
buffer_end - source_it;
196 _ASSERTE(mb_buf_used + bytes_to_add < mb_buf_size);
197 for (
int i = 0;
i < bytes_to_add; ++
i)
202 result.char_count +=
static_cast<DWORD>(bytes_to_add);
209 const auto available_bytes =
buffer_end - source_it;
210 if (mb_len <= (available_bytes))
214 const char*
str = source_it;
223 source_it += (mb_len - 1);
229 for (
int i = 0;
i < available_bytes; ++
i)
234 result.char_count +=
static_cast<DWORD>(available_bytes);
247 mb_buffer[1] = *source_it;
299 console_cp, 0, wc, wc_used, mb_buffer,
sizeof(mb_buffer),
nullptr,
nullptr));
305 if (!
WriteFile(os_handle, mb_buffer,
size, &written,
nullptr))
331 wchar_t const cr =
CR;
332 if (!
WriteFile(os_handle, &cr, 1, &written,
nullptr))
364 write_result
result = { 0 };
371 wchar_t const c = *
reinterpret_cast<wchar_t const*
>(
pch);
414 write_result
result = { 0 };
423 char*
const lfbuf_end = lfbuf +
sizeof(lfbuf) - 1;
427 char* lfbuf_it = lfbuf;
428 while (lfbuf_it < lfbuf_end && source_it <
buffer_end)
430 char const c = *source_it++;
441 DWORD const lfbuf_length =
static_cast<DWORD>(lfbuf_it - lfbuf);
444 if (!
WriteFile(os_handle, lfbuf, lfbuf_length, &written,
nullptr))
450 result.char_count += written;
451 if (written < lfbuf_length)
471 write_result
result = { 0 };
473 wchar_t const* source_it =
reinterpret_cast<wchar_t const*
>(
buffer);
485 wchar_t* lfbuf_it = lfbuf;
486 while (lfbuf_it < lfbuf_end && source_it <
buffer_end)
488 wchar_t const c = *source_it++;
501 DWORD const lfbuf_length =
static_cast<DWORD>(lfbuf_it - lfbuf) *
sizeof(
wchar_t);
506 if (!
WriteFile(os_handle, lfbuf, lfbuf_length, &written,
nullptr))
512 result.char_count += written;
513 if (written < lfbuf_length)
533 write_result
result = { 0 };
535 wchar_t const* source_it =
reinterpret_cast<wchar_t const*
>(
buffer);
548 wchar_t const* utf16_buf_end = utf16_buf + (
BUF_SIZE / 6 - 1);
552 wchar_t* utf16_buf_it = utf16_buf;
553 while (utf16_buf_it < utf16_buf_end && source_it <
buffer_end)
555 wchar_t const c = *source_it++;
563 *utf16_buf_it++ =
CR;
570 DWORD const utf16_buf_length =
static_cast<DWORD>(utf16_buf_it - utf16_buf);
586 if (bytes_converted == 0)
600 for (
DWORD bytes_written = 0; bytes_written < bytes_converted; )
602 char const*
const current = utf8_buf + bytes_written;
603 DWORD const current_size = bytes_converted - bytes_written;
612 bytes_written += written;
633 write_result
result = { 0 };
670 char const*
const char_buffer =
static_cast<char const*
>(
buffer);
679 write_result
result = { 0 };
719 if (
result.char_count == 0)
722 if (
result.error_code != 0)
730 ptd.get_doserrno().set(
result.error_code);
749 ptd.get_doserrno().set(0);
return __acrt_WideCharToMultiByte(code_page, 0, buffer.get(), -1, result_size !=0 ? result :nullptr, result_size, nullptr, nullptr)
_Check_return_ __forceinline unsigned short __cdecl _isleadbyte_fast_internal(_In_ unsigned char const c, _In_ _locale_t const locale)
_Check_return_opt_ __int64 __cdecl _lseeki64_nolock_internal(_In_ int _FileHandle, _In_ __int64 _Offset, _In_ int _Origin, _Inout_ __crt_cached_ptd_host &_Ptd)
#define _dbcsBufferUsed(i)
__inline char _utf8_no_of_trailbytes(const unsigned char c)
void __cdecl __acrt_lowio_lock_fh(_In_ int _FileHandle)
void __cdecl __acrt_lowio_unlock_fh(_In_ int _FileHandle)
#define _UCRT_VALIDATE_CLEAR_OSSERR_RETURN(ptd, expr, errorcode, retexpr)
#define _UCRT_CHECK_FH_CLEAR_OSSERR_RETURN(ptd, handle, errorcode, retexpr)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
#define ERROR_ACCESS_DENIED
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
void __cdecl __acrt_errno_map_os_error_ptd(unsigned long const oserrno, __crt_cached_ptd_host &ptd)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static int is_utf8(const char *src)
int __cdecl _mbtowc_internal(wchar_t *pwc, const char *s, size_t n, __crt_cached_ptd_host &ptd)
struct task_struct * current
size_t __cdecl __mbsrtowcs_utf8(wchar_t *dst, const char **src, size_t len, mbstate_t *ps, __crt_cached_ptd_host &ptd)
#define _Pre_satisfies_(e)
#define _Analysis_assume_
_Check_return_opt_ _CRTIMP wint_t __cdecl _putwch_nolock(wchar_t _WCh)
_Check_return_ _CRTIMP int __cdecl _isatty(_In_ int _FileHandle)
static write_result __cdecl write_text_ansi_nolock(int const fh, _In_reads_(buffer_size) char const *const buffer, unsigned const buffer_size)
static size_t const BUF_SIZE
static write_result __cdecl write_text_utf16le_nolock(int const fh, _In_reads_(buffer_size) char const *const buffer, unsigned const buffer_size)
int __cdecl _write(int const fh, void const *const buffer, unsigned const size)
static bool __cdecl write_requires_double_translation_nolock(int const fh, __crt_cached_ptd_host &ptd)
static write_result __cdecl write_text_utf8_nolock(int const fh, _In_reads_(buffer_size) char const *const buffer, unsigned const buffer_size)
int __cdecl _write_internal(int const fh, void const *const buffer, unsigned const size, __crt_cached_ptd_host &ptd)
static write_result __cdecl write_double_translated_ansi_nolock(int const fh, _In_reads_(buffer_size) char const *const buffer, unsigned const buffer_size, __crt_cached_ptd_host &ptd)
int __cdecl _write_nolock(int const fh, void const *const buffer, unsigned const buffer_size, __crt_cached_ptd_host &ptd)
static write_result __cdecl write_double_translated_unicode_nolock(_In_reads_(buffer_size) char const *const buffer, _In_ _Pre_satisfies_((buffer_size % 2)==0) unsigned const buffer_size)
static write_result __cdecl write_binary_nolock(int const fh, _In_reads_(buffer_size) char const *const buffer, unsigned const buffer_size)
wchar_t const *const size_t const buffer_size
DWORD WINAPI GetLastError(void)