ReactOS 0.4.16-dev-853-g88d9285
cputws.cpp
Go to the documentation of this file.
1//
2// cputws.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines _cputws(), which writes a wide string directly to the console.
7//
8#include <conio.h>
9#include <errno.h>
11#include <limits.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15// Writes the given string directly to the console. No newline is appended.
16//
17// Returns 0 on success; nonzero on failure.
18extern "C" int __cdecl _cputws(wchar_t const* string)
19{
20 _VALIDATE_CLEAR_OSSERR_RETURN((string != nullptr), EINVAL, -1);
21
23 return -1;
24
25 // Write string to console file handle:
26 size_t length = wcslen(string);
27
29
30 int result = 0;
31
32 __try
33 {
34 while (length > 0)
35 {
36 static size_t const max_write_bytes = 65535;
37 static size_t const max_write_wchars = max_write_bytes / sizeof(wchar_t);
38
39 DWORD const wchars_to_write = length > max_write_wchars
40 ? max_write_wchars
41 : static_cast<DWORD>(length);
42
43 DWORD wchars_written;
45 string,
46 wchars_to_write,
47 &wchars_written) == FALSE)
48 {
49 result = -1;
50 __leave;
51 }
52
53 string += wchars_to_write;
54 length -= wchars_to_write;
55 }
56 }
58 {
60 }
62
63 return result;
64}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
void __cdecl __acrt_unlock(_In_ __acrt_lock_id lock)
Definition: locks.cpp:57
@ __acrt_conio_lock
int __cdecl _cputws(wchar_t const *string)
Definition: cputws.cpp:18
__acrt_lock(__acrt_heap_lock)
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL __cdecl __dcrt_lowio_ensure_console_output_initialized()
Definition: initcon.cpp:31
BOOL __cdecl __dcrt_write_console(_In_ void const *lpBuffer, _In_ DWORD nNumberOfCharsToWrite, _Out_ LPDWORD lpNumberOfCharsWritten)
Definition: initcon.cpp:67
#define _VALIDATE_CLEAR_OSSERR_RETURN(expr, errorcode, retexpr)
#define __try
Definition: pseh2_64.h:172
#define __leave
Definition: pseh2_64.h:176
#define __endtry
Definition: pseh2_64.h:175
#define __finally
Definition: pseh2_64.h:174
#define wchar_t
Definition: wchar.h:102