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 //===----------------------------------------------------------------------===//
13 #include "lldb/Host/Windows/win32.h" // For O_NOCTTY
16 #include "lldb/Core/Stream.h"
17 #include "lldb/Target/FileAction.h"
19 using namespace lldb_private;
21 //----------------------------------------------------------------------------
22 // FileAction member functions
23 //----------------------------------------------------------------------------
25 FileAction::FileAction() :
26 m_action(eFileActionNone),
36 m_action = eFileActionNone;
43 FileAction::GetPath() const
45 return m_file_spec.GetCString();
49 FileAction::GetFileSpec() const
55 FileAction::Open(int fd, const FileSpec &file_spec, bool read, bool write)
57 if ((read || write) && fd >= 0 && file_spec)
59 m_action = eFileActionOpen;
62 m_arg = O_NOCTTY | O_CREAT | O_RDWR;
64 m_arg = O_NOCTTY | O_RDONLY;
66 m_arg = O_NOCTTY | O_CREAT | O_WRONLY;
67 m_file_spec = file_spec;
78 FileAction::Close(int fd)
83 m_action = eFileActionClose;
90 FileAction::Duplicate(int fd, int dup_fd)
93 if (fd >= 0 && dup_fd >= 0)
95 m_action = eFileActionDuplicate;
103 FileAction::Dump(Stream &stream) const
105 stream.PutCString("file action: ");
108 case eFileActionClose:
109 stream.Printf("close fd %d", m_fd);
111 case eFileActionDuplicate:
112 stream.Printf("duplicate fd %d to %d", m_fd, m_arg);
114 case eFileActionNone:
115 stream.PutCString("no action");
117 case eFileActionOpen:
118 stream.Printf("open fd %d with '%s', OFLAGS = 0x%x",
119 m_fd, m_file_spec.GetCString(), m_arg);