1 //===-- StreamFile.cpp ----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/StreamFile.h"
10 #include "lldb/Host/FileSystem.h"
11 #include "lldb/Utility/Log.h"
16 using namespace lldb_private;
18 StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
19 : Stream(flags, addr_size, byte_order) {
20 m_file_sp = std::make_shared<File>();
23 StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() {
25 std::make_shared<NativeFile>(fd, File::eOpenOptionWrite, transfer_ownership);
28 StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {
29 m_file_sp = std::make_shared<NativeFile>(fh, transfer_ownership);
32 StreamFile::StreamFile(const char *path, File::OpenOptions options,
35 auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);
37 m_file_sp = std::move(file.get());
39 // TODO refactor this so the error gets popagated up instead of logged here.
40 LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST), file.takeError(),
41 "Cannot open {1}: {0}", path);
42 m_file_sp = std::make_shared<File>();
46 StreamFile::~StreamFile() {}
48 void StreamFile::Flush() { m_file_sp->Flush(); }
50 size_t StreamFile::WriteImpl(const void *s, size_t length) {
51 m_file_sp->Write(s, length);