[libc] Use best-fit binary trie to make malloc logarithmic (#106259)
[llvm-project.git] / libc / src / stdio / generic / fputs.cpp
blob8aef7683b3ce393c84e5f195a57f89e7a1ae5836
1 //===-- Implementation of fputs -------------------------------------------===//
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/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"
16 #include <stddef.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.
32 return EOF;
34 return 0;
37 } // namespace LIBC_NAMESPACE_DECL