/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/StreamFile.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- StreamFile.cpp ----------------------------------------------------===// |
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 "lldb/Core/StreamFile.h" |
10 | | #include "lldb/Host/FileSystem.h" |
11 | | #include "lldb/Utility/LLDBLog.h" |
12 | | #include "lldb/Utility/Log.h" |
13 | | |
14 | | #include <cstdio> |
15 | | |
16 | | using namespace lldb; |
17 | | using namespace lldb_private; |
18 | | |
19 | | StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) |
20 | 0 | : Stream(flags, addr_size, byte_order) { |
21 | 0 | m_file_sp = std::make_shared<File>(); |
22 | 0 | } |
23 | | |
24 | 0 | StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() { |
25 | 0 | m_file_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly, |
26 | 0 | transfer_ownership); |
27 | 0 | } |
28 | | |
29 | 12.0k | StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() { |
30 | 12.0k | m_file_sp = std::make_shared<NativeFile>(fh, transfer_ownership); |
31 | 12.0k | } |
32 | | |
33 | | StreamFile::StreamFile(const char *path, File::OpenOptions options, |
34 | | uint32_t permissions) |
35 | 17 | : Stream() { |
36 | 17 | auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions); |
37 | 17 | if (file) |
38 | 17 | m_file_sp = std::move(file.get()); |
39 | 0 | else { |
40 | | // TODO refactor this so the error gets popagated up instead of logged here. |
41 | 0 | LLDB_LOG_ERROR(GetLog(LLDBLog::Host), file.takeError(), |
42 | 0 | "Cannot open {1}: {0}", path); |
43 | 0 | m_file_sp = std::make_shared<File>(); |
44 | 0 | } |
45 | 17 | } |
46 | | |
47 | 18.9k | StreamFile::~StreamFile() = default; |
48 | | |
49 | 10.8k | void StreamFile::Flush() { m_file_sp->Flush(); } |
50 | | |
51 | 49.5k | size_t StreamFile::WriteImpl(const void *s, size_t length) { |
52 | 49.5k | m_file_sp->Write(s, length); |
53 | 49.5k | return length; |
54 | 49.5k | } |