1 //===-- Implementation of fputs -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/fputs.h"
10 #include "src/__support/CPP/string_view.h"
11 #include "src/__support/File/file.h"
13 #include "hdr/types/FILE.h"
14 #include "src/__support/macros/config.h"
15 #include "src/errno/libc_errno.h"
18 namespace LIBC_NAMESPACE_DECL
{
20 LLVM_LIBC_FUNCTION(int, fputs
,
21 (const char *__restrict str
, ::FILE *__restrict stream
)) {
22 cpp::string_view
str_view(str
);
24 auto result
= reinterpret_cast<LIBC_NAMESPACE::File
*>(stream
)->write(
25 str
, str_view
.size());
26 if (result
.has_error())
27 libc_errno
= result
.error
;
28 size_t written
= result
.value
;
30 if (str_view
.size() != written
) {
31 // The stream should be in an error state in this case.
37 } // namespace LIBC_NAMESPACE_DECL