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
47 return m_path.c_str();
51 FileAction::Open(int fd, const char *path, bool read, bool write)
53 if ((read || write) && fd >= 0 && path && path[0])
55 m_action = eFileActionOpen;
58 m_arg = O_NOCTTY | O_CREAT | O_RDWR;
60 m_arg = O_NOCTTY | O_RDONLY;
62 m_arg = O_NOCTTY | O_CREAT | O_WRONLY;
74 FileAction::Close(int fd)
79 m_action = eFileActionClose;
86 FileAction::Duplicate(int fd, int dup_fd)
89 if (fd >= 0 && dup_fd >= 0)
91 m_action = eFileActionDuplicate;
99 FileAction::Dump(Stream &stream) const
101 stream.PutCString("file action: ");
104 case eFileActionClose:
105 stream.Printf("close fd %d", m_fd);
107 case eFileActionDuplicate:
108 stream.Printf("duplicate fd %d to %d", m_fd, m_arg);
110 case eFileActionNone:
111 stream.PutCString("no action");
113 case eFileActionOpen:
114 stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd, m_path.c_str(), m_arg);