[Lldb-commits] [lldb] r182538 - Cleaned up the File API a bit.

Greg Clayton gclayton at apple.com
Wed May 22 16:30:09 PDT 2013


Author: gclayton
Date: Wed May 22 18:30:09 2013
New Revision: 182538

URL: http://llvm.org/viewvc/llvm-project?rev=182538&view=rev
Log:
Cleaned up the File API a bit.


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=182538&r1=182537&r2=182538&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/File.h (original)
+++ lldb/trunk/include/lldb/Host/File.h Wed May 22 18:30:09 2013
@@ -282,17 +282,19 @@ public:
     /// @see File::Read (void *, size_t, off_t &)
     /// @see File::Write (const void *, size_t, off_t &)
     ///
-    /// @param[in/out] offset
+    /// @param[in] offset
     ///     The offset to seek to within the file relative to the 
-    ///     beginning of the file which gets filled in the the resulting
-    ///     absolute file offset.
+    ///     beginning of the file.
+    ///
+    /// @param[in] error_ptr
+    ///     A pointer to a lldb_private::Error object that will be
+    ///     filled in if non-NULL.
     ///
     /// @return
-    ///     An error object that indicates success or the reason for 
-    ///     failure.
+    ///     The resulting seek offset, or -1 on error.
     //------------------------------------------------------------------
-    Error
-    SeekFromStart (off_t& offset);
+    off_t
+    SeekFromStart (off_t offset, Error *error_ptr = NULL);
     
     //------------------------------------------------------------------
     /// Seek to an offset relative to the current file position.
@@ -303,17 +305,19 @@ public:
     /// @see File::Read (void *, size_t, off_t &)
     /// @see File::Write (const void *, size_t, off_t &)
     ///
-    /// @param[in/out] offset
+    /// @param[in] offset
     ///     The offset to seek to within the file relative to the 
-    ///     current file position. On return this parameter gets filled 
-    ///     in the the resulting absolute file offset.
+    ///     current file position.
+    ///
+    /// @param[in] error_ptr
+    ///     A pointer to a lldb_private::Error object that will be
+    ///     filled in if non-NULL.
     ///
     /// @return
-    ///     An error object that indicates success or the reason for 
-    ///     failure.
+    ///     The resulting seek offset, or -1 on error.
     //------------------------------------------------------------------
-    Error
-    SeekFromCurrent (off_t& offset);
+    off_t
+    SeekFromCurrent (off_t offset, Error *error_ptr = NULL);
     
     //------------------------------------------------------------------
     /// Seek to an offset relative to the end of the file.
@@ -329,12 +333,15 @@ public:
     ///     end of the file which gets filled in the the resulting
     ///     absolute file offset.
     ///
+    /// @param[in] error_ptr
+    ///     A pointer to a lldb_private::Error object that will be
+    ///     filled in if non-NULL.
+    ///
     /// @return
-    ///     An error object that indicates success or the reason for 
-    ///     failure.
+    ///     The resulting seek offset, or -1 on error.
     //------------------------------------------------------------------
-    Error
-    SeekFromEnd (off_t& offset);
+    off_t
+    SeekFromEnd (off_t offset, Error *error_ptr = NULL);
 
     //------------------------------------------------------------------
     /// Read bytes from a file from the specified file offset.

Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=182538&r1=182537&r2=182538&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Wed May 22 18:30:09 2013
@@ -318,58 +318,109 @@ File::GetFileSpec (FileSpec &file_spec)
     return error;
 }
 
-Error
-File::SeekFromStart (off_t& offset)
+off_t
+File::SeekFromStart (off_t offset, Error *error_ptr)
 {
-    Error error;
+    off_t result = 0;
     if (DescriptorIsValid())
     {
-        offset = ::lseek (m_descriptor, offset, SEEK_SET);
+        result = ::lseek (m_descriptor, offset, SEEK_SET);
 
-        if (offset == -1)
-            error.SetErrorToErrno();
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    else 
+    else if (StreamIsValid ())
     {
-        error.SetErrorString("invalid file handle");
+        result = ::fseek(m_stream, offset, SEEK_SET);
+        
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    return error;
+    else if (error_ptr)
+    {
+        error_ptr->SetErrorString("invalid file handle");
+    }
+    return result;
 }
 
-Error
-File::SeekFromCurrent (off_t& offset)
+off_t
+File::SeekFromCurrent (off_t offset,  Error *error_ptr)
 {
-    Error error;
+    off_t result = -1;
     if (DescriptorIsValid())
     {
-        offset = ::lseek (m_descriptor, offset, SEEK_CUR);
+        result = ::lseek (m_descriptor, offset, SEEK_CUR);
         
-        if (offset == -1)
-            error.SetErrorToErrno();
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    else 
+    else if (StreamIsValid ())
     {
-        error.SetErrorString("invalid file handle");
+        result = ::fseek(m_stream, offset, SEEK_CUR);
+        
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    return error;
+    else if (error_ptr)
+    {
+        error_ptr->SetErrorString("invalid file handle");
+    }
+    return result;
 }
 
-Error
-File::SeekFromEnd (off_t& offset)
+off_t
+File::SeekFromEnd (off_t offset, Error *error_ptr)
 {
-    Error error;
+    off_t result = -1;
     if (DescriptorIsValid())
     {
-        offset = ::lseek (m_descriptor, offset, SEEK_END);
+        result = ::lseek (m_descriptor, offset, SEEK_END);
         
-        if (offset == -1)
-            error.SetErrorToErrno();
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    else 
+    else if (StreamIsValid ())
     {
-        error.SetErrorString("invalid file handle");
+        result = ::fseek(m_stream, offset, SEEK_END);
+        
+        if (error_ptr)
+        {
+            if (result == -1)
+                error_ptr->SetErrorToErrno();
+            else
+                error_ptr->Clear();
+        }
     }
-    return error;
+    else if (error_ptr)
+    {
+        error_ptr->SetErrorString("invalid file handle");
+    }
+    return result;
 }
 
 Error





More information about the lldb-commits mailing list