summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StreamFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Core/StreamFile.cpp')
-rw-r--r--lldb/source/Core/StreamFile.cpp105
1 files changed, 16 insertions, 89 deletions
diff --git a/lldb/source/Core/StreamFile.cpp b/lldb/source/Core/StreamFile.cpp
index 5fb42d94703..0d5750801aa 100644
--- a/lldb/source/Core/StreamFile.cpp
+++ b/lldb/source/Core/StreamFile.cpp
@@ -8,13 +8,14 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/StreamFile.h"
-#include "lldb/Host/Config.h"
-#include <stdio.h>
// C Includes
+#include <stdio.h>
// C++ Includes
// Other libraries and framework includes
// Project includes
+#include "lldb/Core/Error.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -24,122 +25,48 @@ using namespace lldb_private;
//----------------------------------------------------------------------
StreamFile::StreamFile () :
Stream (),
- m_file (NULL),
- m_close_file (false),
- m_path_name ()
+ m_file ()
{
}
-StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order, FILE *f) :
+StreamFile::StreamFile (uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
Stream (flags, addr_size, byte_order),
- m_file (f),
- m_close_file (false),
- m_path_name ()
+ m_file ()
{
}
-StreamFile::StreamFile(FILE *f, bool tranfer_ownership) :
+StreamFile::StreamFile (int fd, bool transfer_ownership) :
Stream (),
- m_file (f),
- m_close_file (tranfer_ownership),
- m_path_name ()
+ m_file (fd, transfer_ownership)
{
}
-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_close_file(false),
- m_path_name (path)
+StreamFile::StreamFile (FILE *fh, bool transfer_ownership) :
+ Stream (),
+ m_file (fh, transfer_ownership)
{
- Open(path, permissions);
}
-StreamFile::StreamFile(const char *path, const char *permissions) :
+StreamFile::StreamFile (const char *path) :
Stream (),
- m_file (NULL),
- m_close_file(false),
- m_path_name (path)
+ m_file (path, File::eOpenOptionWrite | File::eOpenOptionCanCreate, File::ePermissionsDefault)
{
- 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::SetLineBuffered ()
-{
- // TODO: check if we can get rid of this LLDB_CONFIG if we do a:
- // setvbuf(m_file, (char *)NULL, _IOLBF, 0);
-#ifdef LLDB_CONFIG_SUPPORTS_SETLINEBUFFERED
- if (m_file != NULL)
- setlinebuf (m_file);
-#endif // #ifdef LLDB_CONFIG_SUPPORTS_SETLINEBUFFERED
}
void
StreamFile::Flush ()
{
- if (m_file)
- ::fflush (m_file);
+ m_file.Flush();
}
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();
+ m_file.Write (s, length);
+ return length;
}
OpenPOWER on IntegriCloud