diff options
| -rw-r--r-- | lldb/include/lldb/Host/File.h | 43 | ||||
| -rw-r--r-- | lldb/source/Host/common/File.cpp | 105 |
2 files changed, 103 insertions, 45 deletions
diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index a0e625771fa..df7fe92cccb 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -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. diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index d0512192a37..c0d3c290f4c 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -318,58 +318,109 @@ File::GetFileSpec (FileSpec &file_spec) const 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 |

