ReactOS 0.4.16-dev-852-gcfcc8d8
puts.cpp
Go to the documentation of this file.
1//
2// puts.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines puts(), which writes a string to stdout.
7//
10
11
12
13// Writes a string to stdout. Does not write the string's null terminator, but
14// _does_ append a newline to the output. Return 0 on success; EOF on failure.
15static int __cdecl _puts_internal(char const* const string, __crt_cached_ptd_host& ptd)
16{
17 _UCRT_VALIDATE_RETURN(ptd, string != nullptr, EINVAL, EOF);
18
19 FILE* const stream = stdout;
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
30 // If we failed to write the entire string, or if we fail to write the
31 // newline, reset the buffering and return failure:
32 if (bytes_written != length || _fputc_nolock_internal('\n', stream, ptd) == EOF)
33 {
34 return EOF;
35 }
36
37 return 0;
38 });
39}
40
41extern "C" int __cdecl puts(char const* const string)
42{
43 __crt_cached_ptd_host ptd;
44 return _puts_internal(string, ptd);
45}
#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 _fputc_nolock_internal(int const c, FILE *const public_stream, __crt_cached_ptd_host &ptd)
Definition: fputc.cpp:12
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define stdout
Definition: stdio.h:99
#define EOF
Definition: stdio.h:24
int __cdecl puts(char const *const string)
Definition: puts.cpp:41
static int __cdecl _puts_internal(char const *const string, __crt_cached_ptd_host &ptd)
Definition: puts.cpp:15
Definition: parse.h:23