1//===-- StreamFile.h --------------------------------------------*- C++ -*-===// 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#ifndef LLDB_HOST_STREAMFILE_H 10#define LLDB_HOST_STREAMFILE_H 11 12#include "lldb/Host/File.h" 13#include "lldb/Utility/Stream.h" 14#include "lldb/lldb-defines.h" 15#include "lldb/lldb-enumerations.h" 16 17#include <cstdint> 18#include <cstdio> 19 20namespace lldb_private { 21 22class StreamFile : public Stream { 23public: 24 StreamFile(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order); 25 26 StreamFile(int fd, bool transfer_ownership); 27 28 StreamFile(const char *path, File::OpenOptions options, 29 uint32_t permissions = lldb::eFilePermissionsFileDefault); 30 31 StreamFile(FILE *fh, bool transfer_ownership); 32 33 StreamFile(std::shared_ptr<File> file) : m_file_sp(file) { assert(file); }; 34 35 ~StreamFile() override; 36 37 File &GetFile() { return *m_file_sp; } 38 39 const File &GetFile() const { return *m_file_sp; } 40 41 std::shared_ptr<File> GetFileSP() { return m_file_sp; } 42 43 void Flush() override; 44 45protected: 46 // Classes that inherit from StreamFile can see and modify these 47 std::shared_ptr<File> m_file_sp; // never NULL 48 size_t WriteImpl(const void *s, size_t length) override; 49 50private: 51 StreamFile(const StreamFile &) = delete; 52 const StreamFile &operator=(const StreamFile &) = delete; 53}; 54 55} // namespace lldb_private 56 57#endif // LLDB_HOST_STREAMFILE_H 58