[Lldb-commits] [lldb] r125106 - in /lldb/trunk: include/lldb/Host/File.h source/Host/common/File.cpp
Greg Clayton
gclayton at apple.com
Tue Feb 8 11:10:54 PST 2011
Author: gclayton
Date: Tue Feb 8 13:10:53 2011
New Revision: 125106
URL: http://llvm.org/viewvc/llvm-project?rev=125106&view=rev
Log:
Added a few more calls to the File abtract class for seeking, syncing and
getting the file spec from the file descriptor.
Modified:
lldb/trunk/include/lldb/Host/File.h
lldb/trunk/source/Host/common/File.cpp
Modified: lldb/trunk/include/lldb/Host/File.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/File.h?rev=125106&r1=125105&r2=125106&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/File.h (original)
+++ lldb/trunk/include/lldb/Host/File.h Tue Feb 8 13:10:53 2011
@@ -53,9 +53,7 @@
ePermissionsWorldExecute = (1u << 8)
};
- File() :
- m_file_spec (),
- m_file_desc (-1)
+ File() : m_file_desc (-1)
{
}
@@ -145,11 +143,8 @@
/// @return
/// A reference to the file specification object.
//------------------------------------------------------------------
- const FileSpec &
- GetFileSpec () const
- {
- return m_file_spec;
- }
+ Error
+ GetFileSpec (FileSpec &file_spec) const;
Error
Open (const char *path,
@@ -165,12 +160,23 @@
Error
Write (const void *src, size_t &num_bytes);
+ Error
+ SeekFromStart (off_t& offset);
+
+ Error
+ SeekFromCurrent (off_t& offset);
+
+ Error
+ SeekFromEnd (off_t& offset);
+
+ Error
+ Sync ();
+
protected:
//------------------------------------------------------------------
// Member variables
//------------------------------------------------------------------
- FileSpec m_file_spec; ///< The file specific for the current file (if any)
- int m_file_desc; ///< The open file handle or NULL if the file isn't opened
+ int m_file_desc; ///< The open file handle or NULL if the file isn't opened
};
} // namespace lldb_private
Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=125106&r1=125105&r2=125106&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Tue Feb 8 13:10:53 2011
@@ -18,7 +18,6 @@
using namespace lldb_private;
File::File(const char *path, uint32_t options, uint32_t permissions) :
- m_file_spec (path, false),
m_file_desc (-1)
{
Open (path, options, permissions);
@@ -80,8 +79,6 @@
m_file_desc = ::open(path, oflag, mode);
if (m_file_desc == -1)
error.SetErrorToErrno();
- else
- m_file_spec.SetFile (path, false);
return error;
}
@@ -94,10 +91,101 @@
{
if (::close (m_file_desc) != 0)
error.SetErrorToErrno();
+ m_file_desc = -1;
+ }
+ return error;
+}
+
+
+Error
+File::GetFileSpec (FileSpec &file_spec) const
+{
+ Error error;
+ if (IsValid ())
+ {
+ char path[PATH_MAX];
+ if (::fcntl(m_file_desc, F_GETPATH, path) == -1)
+ error.SetErrorToErrno();
+ else
+ file_spec.SetFile (path, false);
+ }
+ else
+ error.SetErrorString("invalid file handle");
+
+ if (error.Fail())
+ file_spec.Clear();
+ return error;
+}
+
+Error
+File::SeekFromStart (off_t& offset)
+{
+ Error error;
+ if (IsValid ())
+ {
+ offset = ::lseek (m_file_desc, offset, SEEK_SET);
+
+ if (offset == -1)
+ error.SetErrorToErrno();
+ }
+ else
+ {
+ error.SetErrorString("invalid file handle");
+ }
+ return error;
+}
+
+Error
+File::SeekFromCurrent (off_t& offset)
+{
+ Error error;
+ if (IsValid ())
+ {
+ offset = ::lseek (m_file_desc, offset, SEEK_CUR);
+
+ if (offset == -1)
+ error.SetErrorToErrno();
+ }
+ else
+ {
+ error.SetErrorString("invalid file handle");
+ }
+ return error;
+}
+
+Error
+File::SeekFromEnd (off_t& offset)
+{
+ Error error;
+ if (IsValid ())
+ {
+ offset = ::lseek (m_file_desc, offset, SEEK_CUR);
+
+ if (offset == -1)
+ error.SetErrorToErrno();
+ }
+ else
+ {
+ error.SetErrorString("invalid file handle");
+ }
+ return error;
+}
+
+Error
+File::Sync ()
+{
+ Error error;
+ if (IsValid ())
+ {
+ if (::fsync (m_file_desc) == -1)
+ error.SetErrorToErrno();
+ }
+ else
+ {
+ error.SetErrorString("invalid file handle");
}
return error;
}
-
Error
File::Read (void *buf, size_t &num_bytes)
{
More information about the lldb-commits
mailing list