summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StreamFile.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-06-08 16:52:24 +0000
committerChris Lattner <sabre@nondot.org>2010-06-08 16:52:24 +0000
commit30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c (patch)
treef70013106f6a461a14abcd71c65f48a95a2979a6 /lldb/source/Core/StreamFile.cpp
parent312c4c799da215b337f790fda330f70c4aa757cf (diff)
downloadbcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.tar.gz
bcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.zip
Initial checkin of lldb code from internal Apple repo.
llvm-svn: 105619
Diffstat (limited to 'lldb/source/Core/StreamFile.cpp')
-rw-r--r--lldb/source/Core/StreamFile.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/lldb/source/Core/StreamFile.cpp b/lldb/source/Core/StreamFile.cpp
new file mode 100644
index 00000000000..9c6c508b49e
--- /dev/null
+++ b/lldb/source/Core/StreamFile.cpp
@@ -0,0 +1,132 @@
+//===-- StreamFile.cpp ------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/StreamFile.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+
+using namespace lldb;
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// StreamFile constructor
+//----------------------------------------------------------------------
+StreamFile::StreamFile () :
+ Stream (),
+ m_file (NULL),
+ m_path_name (),
+ m_close_file (false)
+{
+}
+
+StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order, FILE *f) :
+ Stream (flags, addr_size, byte_order),
+ m_file(f),
+ m_path_name (),
+ m_close_file(false)
+{
+}
+
+StreamFile::StreamFile(FILE *f) :
+ Stream (),
+ m_file(f),
+ m_path_name (),
+ m_close_file(false)
+{
+}
+
+StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order, const char *path, const char *permissions) :
+ Stream (flags, addr_size, byte_order),
+ m_file (NULL),
+ m_path_name (path),
+ m_close_file(false)
+{
+ Open(path, permissions);
+}
+
+StreamFile::StreamFile(const char *path, const char *permissions) :
+ Stream (),
+ m_file (NULL),
+ m_path_name (path),
+ m_close_file(false)
+{
+ Open(path, permissions);
+}
+
+
+StreamFile::~StreamFile()
+{
+ Close ();
+}
+
+void
+StreamFile::Close ()
+{
+ if (m_close_file && m_file != NULL)
+ ::fclose (m_file);
+ m_file = NULL;
+ m_close_file = false;
+}
+
+bool
+StreamFile::Open (const char *path, const char *permissions)
+{
+ Close();
+ if (path && path[0])
+ {
+ if ((m_path_name.size() == 0)
+ || (m_path_name.compare(path) != 0))
+ m_path_name = path;
+ m_file = ::fopen (path, permissions);
+ if (m_file != NULL)
+ m_close_file = true;
+ }
+ return m_file != NULL;
+}
+
+void
+StreamFile::Flush ()
+{
+ if (m_file)
+ ::fflush (m_file);
+}
+
+int
+StreamFile::Write (const void *s, size_t length)
+{
+ if (m_file)
+ return ::fwrite (s, 1, length, m_file);
+ return 0;
+}
+
+FILE *
+StreamFile::GetFileHandle()
+{
+ return m_file;
+}
+
+void
+StreamFile::SetFileHandle (FILE *file, bool close_file)
+{
+ Close();
+ m_file = file;
+ m_close_file = close_file;
+}
+
+const char *
+StreamFile::GetFilePathname ()
+{
+ if (m_path_name.size() == 0)
+ return NULL;
+ else
+ return m_path_name.c_str();
+}
OpenPOWER on IntegriCloud