ReactOS 0.4.16-dev-852-gcfcc8d8
fputs.cpp
Go to the documentation of this file.
1//
2// fputs.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines fputs(), which writes a string to a stream.
7//
10
11
12
13// Writes the given string to the given stream. Does not write the string's null
14// terminator, and does not append a '\n' to the file. Returns a nonnegative
15// value on success; EOF on failure.
16static int __cdecl _fputs_internal(char const* const string, FILE* const stream, __crt_cached_ptd_host& ptd)
17{
18 _UCRT_VALIDATE_RETURN(ptd, string != nullptr, EINVAL, EOF);
21
22 size_t const length = strlen(string);
23
24 return __acrt_lock_stream_and_call(stream, [&]() -> int
25 {
26 __acrt_stdio_temporary_buffering_guard const buffering(stream, ptd);
27
28 size_t const bytes_written = _fwrite_nolock_internal(string, 1, length, stream, ptd);
29 if (bytes_written == length)
30 {
31 return 0;
32 }
33
34 return EOF;
35 });
36}
37
38extern "C" int __cdecl fputs(char const* const string, FILE* const stream)
39{
40 __crt_cached_ptd_host ptd;
41 return _fputs_internal(string, stream, ptd);
42}
#define EINVAL
Definition: acclib.h:90
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define __cdecl
Definition: accygwin.h:79
#define _UCRT_VALIDATE_STREAM_ANSI_RETURN(ptd, stream, errorcode, retexpr)
#define _UCRT_VALIDATE_RETURN(ptd, expr, errorcode, retexpr)
auto __acrt_lock_stream_and_call(FILE *const stream, Action &&action) -> decltype(action())
_Check_return_opt_ size_t __cdecl _fwrite_nolock_internal(_In_reads_bytes_(_ElementSize *_ElementCount) void const *_Buffer, _In_ size_t _ElementSize, _In_ size_t _ElementCount, _Inout_ FILE *_Stream, _Inout_ __crt_cached_ptd_host &_Ptd)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
int __cdecl fputs(char const *const string, FILE *const stream)
Definition: fputs.cpp:38
static int __cdecl _fputs_internal(char const *const string, FILE *const stream, __crt_cached_ptd_host &ptd)
Definition: fputs.cpp:16
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define EOF
Definition: stdio.h:24
Definition: parse.h:23