Reactos
1//
2// fputws.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines fputws(), which writes a wide character string to a stream.
7//
8#include <corecrt_internal_stdio.h>
9#include <corecrt_internal_ptd_propagation.h>
10
11
12
13// Writes the given wide character string to the given stream. Does not write
14// the string's null terminator, and does not append a '\n' to the file. Returns
15// a nonnegative value on success; EOF on failure. (Note well that we return EOF
16// and not WEOF on failure. This is intentional, and is the correct behavior per
17// the C Language Standard).
18static int __cdecl _fputws_internal(wchar_t const* const string, FILE* const stream, __crt_cached_ptd_host& ptd)
19{
20 _UCRT_VALIDATE_RETURN(ptd, string != nullptr, EINVAL, EOF);
21 _UCRT_VALIDATE_RETURN(ptd, stream != nullptr, EINVAL, EOF);
22
23 return __acrt_lock_stream_and_call(stream, [&]() -> int
24 {
25 __acrt_stdio_temporary_buffering_guard const buffering(stream, ptd);
26
27 for (wchar_t const* it = string; *it != L'\0'; ++it)
28 {
29 if (_fputwc_nolock_internal(*it, stream, ptd) == WEOF)
30 {
31 return EOF;
32 }
33 }
34
35 return 0;
36 });
37}
38
39extern "C" int __cdecl fputws(wchar_t const* const string, FILE* const stream)
40{
41 __crt_cached_ptd_host ptd;
42 return _fputws_internal(string, stream, ptd);
43}