1 //===-- StreamFile.cpp ------------------------------------------*- 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 #include "lldb/Core/StreamFile.h" 10 #include "lldb/Host/FileSystem.h" 11 12 #include <stdio.h> 13 14 using namespace lldb; 15 using namespace lldb_private; 16 17 //---------------------------------------------------------------------- 18 // StreamFile constructor 19 //---------------------------------------------------------------------- 20 StreamFile::StreamFile() : Stream(), m_file() {} 21 22 StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) 23 : Stream(flags, addr_size, byte_order), m_file() {} 24 25 StreamFile::StreamFile(int fd, bool transfer_ownership) 26 : Stream(), m_file(fd, transfer_ownership) {} 27 28 StreamFile::StreamFile(FILE *fh, bool transfer_ownership) 29 : Stream(), m_file(fh, transfer_ownership) {} 30 31 StreamFile::StreamFile(const char *path) : Stream(), m_file() { 32 FileSystem::Instance().Open(m_file, FileSpec(path), 33 File::eOpenOptionWrite | 34 File::eOpenOptionCanCreate | 35 File::eOpenOptionCloseOnExec); 36 } 37 38 StreamFile::StreamFile(const char *path, uint32_t options, uint32_t permissions) 39 : Stream(), m_file() { 40 41 FileSystem::Instance().Open(m_file, FileSpec(path), options, permissions); 42 } 43 44 StreamFile::~StreamFile() {} 45 46 void StreamFile::Flush() { m_file.Flush(); } 47 48 size_t StreamFile::WriteImpl(const void *s, size_t length) { 49 m_file.Write(s, length); 50 return length; 51 } 52