1 //===-- Implementation of puts --------------------------------------------===//
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/puts.h"
10 #include "src/__support/CPP/string_view.h"
11 #include "src/__support/File/file.h"
16 namespace __llvm_libc
{
18 LLVM_LIBC_FUNCTION(int, puts
, (const char *__restrict str
)) {
19 cpp::string_view
str_view(str
);
20 auto result
= __llvm_libc::stdout
->write(str
, str_view
.size());
21 if (result
.has_error())
23 size_t written
= result
.value
;
24 if (str_view
.size() != written
) {
25 // The stream should be in an error state in this case.
28 result
= __llvm_libc::stdout
->write("\n", 1);
29 if (result
.has_error())
31 written
= result
.value
;
33 // The stream should be in an error state in this case.
39 } // namespace __llvm_libc