OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 //! a Close(). | 160 //! a Close(). |
161 FileOffset Seek(FileOffset offset, int whence) override; | 161 FileOffset Seek(FileOffset offset, int whence) override; |
162 | 162 |
163 private: | 163 private: |
164 ScopedFileHandle file_; | 164 ScopedFileHandle file_; |
165 WeakFileHandleFileWriter weak_file_handle_file_writer_; | 165 WeakFileHandleFileWriter weak_file_handle_file_writer_; |
166 | 166 |
167 DISALLOW_COPY_AND_ASSIGN(FileWriter); | 167 DISALLOW_COPY_AND_ASSIGN(FileWriter); |
168 }; | 168 }; |
169 | 169 |
170 //! \brief A file writer backed by a standard input/output `FILE*`. | |
171 //! | |
172 //! This class accepts an already-open `FILE*`. It is not responsible for | |
173 //! opening or closing this `FILE*`. Users of this class must ensure that the | |
174 //! `FILE*` is closed appropriately elsewhere. Objects of this class may be used | |
175 //! to write to `FILE*` objects not associated with filesystem-based files, | |
176 //! although special attention should be paid to the Seek() method, which may | |
177 //! not function on `FILE*` objects that do not refer to disk-based files. | |
178 //! | |
179 //! This class is expected to be used when other code is responsible for | |
180 //! opening `FILE*` objects and already provides `FILE*` objects. A good use | |
181 //! would be a WeakStdioFileWriter for `stdout`. | |
182 class WeakStdioFileWriter : public FileWriterInterface { | |
183 public: | |
184 explicit WeakStdioFileWriter(FILE* file); | |
185 ~WeakStdioFileWriter() override; | |
186 | |
187 // FileWriterInterface: | |
188 bool Write(const void* data, size_t size) override; | |
189 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; | |
190 | |
191 // FileSeekerInterface: | |
192 | |
193 //! \copydoc FileWriterInterface::Seek() | |
194 //! | |
195 //! \note This method is only guaranteed to function on `FILE*` objects | |
196 //! referring to disk-based files. | |
197 FileOffset Seek(FileOffset offset, int whence) override; | |
198 | |
199 private: | |
200 FILE* file_; // weak | |
201 | |
202 DISALLOW_COPY_AND_ASSIGN(WeakStdioFileWriter); | |
203 }; | |
204 | |
205 } // namespace crashpad | 170 } // namespace crashpad |
206 | 171 |
207 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ | 172 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ |
OLD | NEW |