OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef CRASHPAD_UTIL_FILE_FILE_READER_H_ | 15 #ifndef CRASHPAD_UTIL_FILE_FILE_READER_H_ |
16 #define CRASHPAD_UTIL_FILE_FILE_READER_H_ | 16 #define CRASHPAD_UTIL_FILE_FILE_READER_H_ |
17 | 17 |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 | 19 |
20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "util/file/file_io.h" | 22 #include "util/file/file_io.h" |
23 #include "util/file/file_seeker.h" | 23 #include "util/file/file_seeker.h" |
24 | 24 |
25 namespace crashpad { | 25 namespace crashpad { |
26 | 26 |
27 //! \brief An interface to read to files and other file-like objects with | 27 //! \brief An interface to read to files and other file-like objects with |
28 //! semantics matching the underlying platform (POSIX or Windows). | 28 //! semantics matching the underlying platform (POSIX or Windows). |
29 class FileReaderInterface : public FileSeekerInterface { | 29 class FileReaderInterface : public virtual FileSeekerInterface { |
30 public: | 30 public: |
31 //! \brief Wraps ReadFile(), or provides an implementation with identical | 31 //! \brief Wraps ReadFile(), or provides an implementation with identical |
32 //! semantics. | 32 //! semantics. |
33 //! | 33 //! |
34 //! \return The number of bytes actually read if the operation succeeded, | 34 //! \return The number of bytes actually read if the operation succeeded, |
35 //! which may be `0` or any positive value less than or equal to \a size. | 35 //! which may be `0` or any positive value less than or equal to \a size. |
36 //! `-1` if the operation failed, with an error message logged. | 36 //! `-1` if the operation failed, with an error message logged. |
37 virtual ssize_t Read(void* data, size_t size) = 0; | 37 virtual ssize_t Read(void* data, size_t size) = 0; |
38 | 38 |
| 39 //! \brief Wraps Read(), ensuring that the read succeeded and exactly \a size |
| 40 //! bytes were read. |
| 41 //! |
| 42 //! Semantically, this behaves as LoggingReadFile(). |
| 43 //! |
| 44 //! \return `true` if the operation succeeded, `false` if it failed, with an |
| 45 //! error message logged. Short reads are treated as failures. |
| 46 bool ReadExactly(void* data, size_t size); |
| 47 |
39 protected: | 48 protected: |
40 ~FileReaderInterface() {} | 49 ~FileReaderInterface() {} |
41 }; | 50 }; |
42 | 51 |
43 //! \brief A file reader backed by a FileHandle. | 52 //! \brief A file reader backed by a FileHandle. |
44 //! | 53 //! |
45 //! FileReader requires users to provide a FilePath to open, but this class | 54 //! FileReader requires users to provide a FilePath to open, but this class |
46 //! accepts an already-open FileHandle instead. Like FileReader, this class may | 55 //! accepts an already-open FileHandle instead. Like FileReader, this class may |
47 //! read from a filesystem-based file, but unlike FileReader, this class is not | 56 //! read from a filesystem-based file, but unlike FileReader, this class is not |
48 //! responsible for opening or closing the file. Users of this class must ensure | 57 //! responsible for opening or closing the file. Users of this class must ensure |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 private: | 140 private: |
132 ScopedFileHandle file_; | 141 ScopedFileHandle file_; |
133 WeakFileHandleFileReader weak_file_handle_file_reader_; | 142 WeakFileHandleFileReader weak_file_handle_file_reader_; |
134 | 143 |
135 DISALLOW_COPY_AND_ASSIGN(FileReader); | 144 DISALLOW_COPY_AND_ASSIGN(FileReader); |
136 }; | 145 }; |
137 | 146 |
138 } // namespace crashpad | 147 } // namespace crashpad |
139 | 148 |
140 #endif // CRASHPAD_UTIL_FILE_FILE_READER_H_ | 149 #endif // CRASHPAD_UTIL_FILE_FILE_READER_H_ |
OLD | NEW |