Index: third_party/crashpad/crashpad/util/file/file_reader.cc |
diff --git a/third_party/crashpad/crashpad/util/file/file_reader.cc b/third_party/crashpad/crashpad/util/file/file_reader.cc |
index 4f5ae773257cfaaa619f119ac3f0121733f0adf6..6f272f013f68574707ab9c77dab39baf73b86b16 100644 |
--- a/third_party/crashpad/crashpad/util/file/file_reader.cc |
+++ b/third_party/crashpad/crashpad/util/file/file_reader.cc |
@@ -20,18 +20,31 @@ |
namespace crashpad { |
-bool FileReaderInterface::ReadExactly(void* data, size_t size) { |
- FileOperationResult expect = base::checked_cast<FileOperationResult>(size); |
- FileOperationResult rv = Read(data, size); |
- if (rv < 0) { |
- // Read() will have logged its own error. |
- return false; |
- } else if (rv != expect) { |
- LOG(ERROR) << "ReadExactly(): expected " << expect << ", observed " << rv; |
- return false; |
+namespace { |
+ |
+class FileReaderReadExactly final : public internal::ReadExactlyInternal { |
+ public: |
+ explicit FileReaderReadExactly(FileReaderInterface* file_reader) |
+ : ReadExactlyInternal(), file_reader_(file_reader) {} |
+ ~FileReaderReadExactly() {} |
+ |
+ private: |
+ // ReadExactlyInternal: |
+ FileOperationResult Read(void* buffer, size_t size, bool can_log) override { |
+ DCHECK(can_log); |
+ return file_reader_->Read(buffer, size); |
} |
- return true; |
+ FileReaderInterface* file_reader_; // weak |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FileReaderReadExactly); |
+}; |
+ |
+} // namespace |
+ |
+bool FileReaderInterface::ReadExactly(void* data, size_t size) { |
+ FileReaderReadExactly read_exactly(this); |
+ return read_exactly.ReadExactly(data, size, true); |
} |
WeakFileHandleFileReader::WeakFileHandleFileReader(FileHandle file_handle) |
@@ -44,13 +57,10 @@ WeakFileHandleFileReader::~WeakFileHandleFileReader() { |
FileOperationResult WeakFileHandleFileReader::Read(void* data, size_t size) { |
DCHECK_NE(file_handle_, kInvalidFileHandle); |
- // Don’t use LoggingReadFile(), which insists on a full read and only returns |
- // a bool. This method permits short reads and returns the number of bytes |
- // read. |
base::checked_cast<FileOperationResult>(size); |
FileOperationResult rv = ReadFile(file_handle_, data, size); |
if (rv < 0) { |
- PLOG(ERROR) << "read"; |
+ PLOG(ERROR) << internal::kNativeReadFunctionName; |
return -1; |
} |
@@ -98,43 +108,4 @@ FileOffset FileReader::Seek(FileOffset offset, int whence) { |
return weak_file_handle_file_reader_.Seek(offset, whence); |
} |
-WeakStdioFileReader::WeakStdioFileReader(FILE* file) |
- : file_(file) { |
-} |
- |
-WeakStdioFileReader::~WeakStdioFileReader() { |
-} |
- |
-FileOperationResult WeakStdioFileReader::Read(void* data, size_t size) { |
- DCHECK(file_); |
- |
- size_t rv = fread(data, 1, size, file_); |
- if (rv != size && ferror(file_)) { |
- STDIO_PLOG(ERROR) << "fread"; |
- return -1; |
- } |
- if (rv > size) { |
- LOG(ERROR) << "fread: expected " << size << ", observed " << rv; |
- return -1; |
- } |
- |
- return rv; |
-} |
- |
-FileOffset WeakStdioFileReader::Seek(FileOffset offset, int whence) { |
- DCHECK(file_); |
- if (fseeko(file_, offset, whence) == -1) { |
- STDIO_PLOG(ERROR) << "fseeko"; |
- return -1; |
- } |
- |
- FileOffset new_offset = ftello(file_); |
- if (new_offset == -1) { |
- STDIO_PLOG(ERROR) << "ftello"; |
- return -1; |
- } |
- |
- return new_offset; |
-} |
- |
} // namespace crashpad |