Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: util/file/file_writer.h

Issue 432003005: Introduce MinidumpWritable, its dependencies, and their tests (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_UTIL_FILE_FILE_WRITER_H_
16 #define CRASHPAD_UTIL_FILE_FILE_WRITER_H_
17
18 #include <fcntl.h>
19 #include <stddef.h>
20 #include <sys/uio.h>
21 #include <unistd.h>
22
23 #include <string>
24 #include <vector>
25
26 #include "base/basictypes.h"
27 #include "base/files/scoped_file.h"
28
29 namespace crashpad {
30
31 //! \brief A version of `iovec` with a `const` #iov_base field.
32 //!
33 //! This structure is intended to be used for write operations.
34 //
35 // Type compatibility with iovec is tested with static assertions in the
36 // implementation file.
37 struct WritableIoVec {
38 //! \brief The base address of a memory region for output.
39 const void* iov_base;
40
41 //! \brief The size of the memory pointed to by #iov_base.
42 size_t iov_len;
43 };
44
45 //! \brief An interface to write to files and other file-like objects with POSIX
46 //! semantics.
47 class FileWriterInterface {
Robert Sesek 2014/08/01 14:38:04 The assumption here is that checking errno is sill
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
48 public:
49 //! \brief Wraps `write()` or provides an alternate implementation with
50 //! identical semantics. This method will write the entire buffer,
51 //! continuing after a short write or after being interrupted.
52 //!
53 //! \return `true` if the operation succeeded, `false` if it failed, with an
54 //! error message logged.
55 virtual bool Write(const void* data, size_t size) = 0;
56
57 //! \brief Wraps `writev()` or provides an alternate implementation with
58 //! identical semantics. This method will write the entire buffer,
59 //! continuing after a short write or after being interrupted.
60 //!
61 //! \return `true` if the operation succeeded, `false` if it failed, with an
62 //! error message logged.
63 //!
64 //! \note The contents of \a iovecs are undefined when this method returns.
65 virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0;
66
67 //! \brief Wraps `lseek()` or provides an alternate implementation with
68 //! identical semantics.
69 //!
70 //! \return The return value of `lseek()`. `-1` on failure, with an error
71 //! message logged.
72 virtual off_t Seek(off_t offset, int whence) = 0;
73
74 protected:
75 ~FileWriterInterface() {}
76 };
77
78 //! \brief A file writer implementation that wraps traditional POSIX file
79 //! operations on files accessed through the filesystem.
80 class FileWriter : public FileWriterInterface {
81 public:
82 FileWriter();
83 ~FileWriter();
84
85 //! \brief Wraps `open()`.
Robert Sesek 2014/08/01 14:38:04 Probably need to mention that you can't call this
86 //!
87 //! \return `true` if the operation succeeded, `false` if it failed, with an
88 //! error message logged.
89 bool Open(const std::string& path, int oflag, mode_t mode);
Robert Sesek 2014/08/01 14:38:04 Any thought on using base::FilePath?
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
90
91 //! \brief Wraps `close().`
92 void Close();
93
94 virtual bool Write(const void* data, size_t size) override;
Robert Sesek 2014/08/01 14:38:04 Style is typically: // FileWriterInterface: And
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
95
96 virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
97
98 virtual off_t Seek(off_t offset, int whence) override;
99
100 private:
101 base::ScopedFD fd_;
102
103 DISALLOW_COPY_AND_ASSIGN(FileWriter);
104 };
105
106 } // namespace crashpad
107
108 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698