[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / src / stdio / puts.cpp
blob57e4919500f5a5687144e3c70ea95a3d853d64e4
1 //===-- Implementation of puts --------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/puts.h"
10 #include "src/__support/CPP/string_view.h"
11 #include "src/__support/File/file.h"
13 #include <errno.h>
14 #include <stdio.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())
22 errno = result.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.
26 return EOF;
28 result = __llvm_libc::stdout->write("\n", 1);
29 if (result.has_error())
30 errno = result.error;
31 written = result.value;
32 if (1 != written) {
33 // The stream should be in an error state in this case.
34 return EOF;
36 return 0;
39 } // namespace __llvm_libc