Path: blob/main/contrib/llvm-project/lldb/source/Host/common/StreamFile.cpp
39606 views
//===-- StreamFile.cpp ----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/StreamFile.h"9#include "lldb/Host/FileSystem.h"10#include "lldb/Utility/LLDBLog.h"11#include "lldb/Utility/Log.h"1213#include <cstdio>1415using namespace lldb;16using namespace lldb_private;1718StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)19: Stream(flags, addr_size, byte_order) {20m_file_sp = std::make_shared<File>();21}2223StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() {24m_file_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly,25transfer_ownership);26}2728StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {29m_file_sp = std::make_shared<NativeFile>(fh, transfer_ownership);30}3132StreamFile::StreamFile(const char *path, File::OpenOptions options,33uint32_t permissions)34: Stream() {35auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);36if (file)37m_file_sp = std::move(file.get());38else {39// TODO refactor this so the error gets popagated up instead of logged here.40LLDB_LOG_ERROR(GetLog(LLDBLog::Host), file.takeError(),41"Cannot open {1}: {0}", path);42m_file_sp = std::make_shared<File>();43}44}4546StreamFile::~StreamFile() = default;4748void StreamFile::Flush() { m_file_sp->Flush(); }4950size_t StreamFile::WriteImpl(const void *s, size_t length) {51m_file_sp->Write(s, length);52return length;53}545556