Reactos
1//
2// putws.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines _putws(), which writes a wide character string to stdout.
7//
8#include <corecrt_internal_stdio.h>
9#include <corecrt_internal_ptd_propagation.h>
10
11
12
13// Writes a wide character string to stdout. Does not write the string's null
14// terminator, but _does_ append a newline to the output. Returns 0 on success;
15// returns WEOF on failure.
16static int __cdecl _putws_internal(wchar_t const* const string, __crt_cached_ptd_host& ptd)
17{
18 _UCRT_VALIDATE_RETURN(ptd, string != nullptr, EINVAL, WEOF);
19
20 FILE* const stream = stdout;
21
22 return __acrt_lock_stream_and_call(stream, [&]() -> int
23 {
24 __acrt_stdio_temporary_buffering_guard const buffering(stream, ptd);
25
26 // Write the string, character-by-character:
27 for (wchar_t const* it = string; *it; ++it)
28 {
29 if (_fputwc_nolock_internal(*it, stream, ptd) == WEOF)
30 {
31 return WEOF;
32 }
33 }
34
35 if (_fputwc_nolock_internal(L'\n', stream, ptd) == WEOF)
36 {
37 return WEOF;
38 }
39
40 return 0;
41 });
42}
43
44extern "C" int __cdecl _putws(wchar_t const* const string)
45{
46 __crt_cached_ptd_host ptd;
47 return _putws_internal(string, ptd);
48}