1 //===-- FileAction.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "lldb/Host/PosixApi.h"
13 #include "lldb/Target/FileAction.h"
14 #include "lldb/Utility/Stream.h"
16 using namespace lldb_private;
18 //----------------------------------------------------------------------------
19 // FileAction member functions
20 //----------------------------------------------------------------------------
22 FileAction::FileAction()
23 : m_action(eFileActionNone), m_fd(-1), m_arg(-1), m_file_spec() {}
25 void FileAction::Clear() {
26 m_action = eFileActionNone;
32 llvm::StringRef FileAction::GetPath() const { return m_file_spec.GetCString(); }
34 const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; }
36 bool FileAction::Open(int fd, const FileSpec &file_spec, bool read,
38 if ((read || write) && fd >= 0 && file_spec) {
39 m_action = eFileActionOpen;
42 m_arg = O_NOCTTY | O_CREAT | O_RDWR;
44 m_arg = O_NOCTTY | O_RDONLY;
46 m_arg = O_NOCTTY | O_CREAT | O_WRONLY;
47 m_file_spec = file_spec;
55 bool FileAction::Close(int fd) {
58 m_action = eFileActionClose;
64 bool FileAction::Duplicate(int fd, int dup_fd) {
66 if (fd >= 0 && dup_fd >= 0) {
67 m_action = eFileActionDuplicate;
74 void FileAction::Dump(Stream &stream) const {
75 stream.PutCString("file action: ");
77 case eFileActionClose:
78 stream.Printf("close fd %d", m_fd);
80 case eFileActionDuplicate:
81 stream.Printf("duplicate fd %d to %d", m_fd, m_arg);
84 stream.PutCString("no action");
87 stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd,
88 m_file_spec.GetCString(), m_arg);