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//===----------------------------------------------------------------------===//
8
9#include "src/stdio/fputs.h"
10#include "src/__support/CPP/string_view.h"
11#include "src/__support/File/file.h"
12
13#include "src/errno/libc_errno.h"
14#include <stdio.h>
15
16namespace LIBC_NAMESPACE {
17
18LLVM_LIBC_FUNCTION(int, fputs,
19 (const char *__restrict str, ::FILE *__restrict stream)) {
20 cpp::string_view str_view(str);
21
22 auto result = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->write(
23 data: str, len: str_view.size());
24 if (result.has_error())
25 libc_errno = result.error;
26 size_t written = result.value;
27
28 if (str_view.size() != written) {
29 // The stream should be in an error state in this case.
30 return EOF;
31 }
32 return 0;
33}
34
35} // namespace LIBC_NAMESPACE
36

source code of libc/src/stdio/generic/fputs.cpp