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 "hdr/types/FILE.h"
14#include "src/__support/libc_errno.h"
15#include "src/__support/macros/config.h"
16#include <stddef.h>
17
18namespace LIBC_NAMESPACE_DECL {
19
20LLVM_LIBC_FUNCTION(int, fputs,
21 (const char *__restrict str, ::FILE *__restrict stream)) {
22 cpp::string_view str_view(str);
23
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;
29
30 if (str_view.size() != written) {
31 // The stream should be in an error state in this case.
32 return EOF;
33 }
34 return 0;
35}
36
37} // namespace LIBC_NAMESPACE_DECL
38

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

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