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, |
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_IO_H_ | 15 #ifndef CRASHPAD_UTIL_FILE_FILE_IO_H_ |
16 #define CRASHPAD_UTIL_FILE_FILE_IO_H_ | 16 #define CRASHPAD_UTIL_FILE_FILE_IO_H_ |
17 | 17 |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 | 19 |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 | 21 |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 #include <windows.h> | 23 #include <windows.h> |
24 #endif | 24 #endif |
25 | 25 |
26 namespace base { | |
27 class FilePath; | |
28 } // namespace base | |
29 | |
26 namespace crashpad { | 30 namespace crashpad { |
27 | 31 |
28 #if defined(OS_POSIX) | 32 #if defined(OS_POSIX) || DOXYGEN |
33 //! \brief Platform-specific alias for a low level file handle. | |
29 using FileHandle = int; | 34 using FileHandle = int; |
30 #elif defined(OS_WIN) | 35 #elif defined(OS_WIN) |
31 using FileHandle = HANDLE; | 36 using FileHandle = HANDLE; |
32 #endif | 37 #endif |
33 | 38 |
39 //! \brief Determines the mode that LoggingOpenFileForWrite uses. | |
Mark Mentovai
2014/12/18 20:24:59
() on function names.
scottmg
2014/12/18 21:18:54
Done.
| |
40 enum FileWriteMode { | |
41 //! \brief Opens the file if it exists and seeks to the end of the file, or | |
Mark Mentovai
2014/12/18 20:24:59
Meh, I don’t know about having this actually do th
scottmg
2014/12/18 21:18:53
OK, removed that part. (Next CL will probably be L
| |
42 //! creates a new file. | |
43 kAppend, | |
44 | |
45 //! \brief Creates a new file. If the file already exists, it will be | |
46 //! overwritten. | |
Mark Mentovai
2014/12/18 20:24:59
Overwritten? What’s the difference between kCreate
scottmg
2014/12/18 21:18:54
I meant for kTruncate to be open-but-must-already-
Mark Mentovai
2014/12/18 21:52:32
scottmg wrote:
| |
47 kCreate, | |
48 | |
49 //! \brief Creates a new file. If the file already exists, the open will fail. | |
50 kCreateNew, | |
51 | |
52 //! \brief Opens an existing file. When the file is opened, it will be | |
53 //! truncated so that its size is zero bytes. | |
54 kTruncate, | |
Mark Mentovai
2014/12/18 20:27:34
Oh, also, these names should be something like kFi
scottmg
2014/12/18 21:18:53
I'll go with enum class then for the excitement an
| |
55 }; | |
Mark Mentovai
2014/12/18 20:24:59
Everything here has the potential to create a file
scottmg
2014/12/18 21:18:53
That sounds right after removing kTruncate. So the
| |
56 | |
34 //! \brief Reads from a file, retrying when interrupted on POSIX or following a | 57 //! \brief Reads from a file, retrying when interrupted on POSIX or following a |
35 //! short read. | 58 //! short read. |
36 //! | 59 //! |
37 //! This function reads into \a buffer, stopping only when \a size bytes have | 60 //! This function reads into \a buffer, stopping only when \a size bytes have |
38 //! been read or when end-of-file has been reached. On Windows, reading from | 61 //! been read or when end-of-file has been reached. On Windows, reading from |
39 //! sockets is not currently supported. | 62 //! sockets is not currently supported. |
40 //! | 63 //! |
41 //! \return The number of bytes read and placed into \a buffer, or `-1` on | 64 //! \return The number of bytes read and placed into \a buffer, or `-1` on |
42 //! error, with `errno` or `GetLastError()` set appropriately. On error, a | 65 //! error, with `errno` or `GetLastError()` set appropriately. On error, a |
43 //! portion of \a file may have been read into \a buffer. | 66 //! portion of \a file may have been read into \a buffer. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 //! \brief Wraps ReadFile(), ensuring that it indicates end-of-file. | 137 //! \brief Wraps ReadFile(), ensuring that it indicates end-of-file. |
115 //! | 138 //! |
116 //! Attempts to read a single byte from \a file, expecting no data to be read. | 139 //! Attempts to read a single byte from \a file, expecting no data to be read. |
117 //! If the underlying ReadFile() fails, or if a byte actually is read, this | 140 //! If the underlying ReadFile() fails, or if a byte actually is read, this |
118 //! function causes execution to terminate without returning. | 141 //! function causes execution to terminate without returning. |
119 //! | 142 //! |
120 //! \sa CheckedReadFile | 143 //! \sa CheckedReadFile |
121 //! \sa ReadFile | 144 //! \sa ReadFile |
122 void CheckedReadFileAtEOF(FileHandle file); | 145 void CheckedReadFileAtEOF(FileHandle file); |
123 | 146 |
147 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs | |
148 //! an error if the operation fails. | |
149 //! | |
150 //! \a write_mode determines the style (clobber, truncate, etc.) that is used | |
Mark Mentovai
2014/12/18 20:24:59
Normally parameters are done with \param[in] style
scottmg
2014/12/18 21:18:54
OK. LMK if you want to change them all and I can d
scottmg
2014/12/18 21:36:45
Answering my own parenthetical, http://www.stack.n
Mark Mentovai
2014/12/18 21:52:32
scottmg wrote:
| |
151 //! to open the file. On POSIX, if \a world_readable, the permissions bits will | |
152 //! be set to 0644, otherwise, 0600. On Windows, the file is always opened in | |
Mark Mentovai
2014/12/18 20:24:59
Numeric literals also get the `backtick` treatment
Mark Mentovai
2014/12/18 20:24:59
“set to” is not totally correct, because the umask
scottmg
2014/12/18 21:18:53
Done.
scottmg
2014/12/18 21:18:53
Attempted improvement.
| |
153 //! binary mode (that is, no CRLF translation). | |
154 //! | |
155 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. | |
156 //! | |
157 //! \sa FileWriteMode | |
158 //! \sa ScopedFD | |
159 //! \sa ScopedFileHANDLE | |
160 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, | |
161 FileWriteMode write_mode, | |
162 bool world_readable); | |
163 | |
164 //! \brief Wraps `open()` or `CreateFile()`, opening an existing file for | |
165 //! reading. Logs an error if the operation fails. | |
166 //! | |
167 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. | |
168 //! | |
169 //! \sa ScopedFD | |
170 //! \sa ScopedFileHANDLE | |
171 FileHandle LoggingOpenFileForRead(const base::FilePath& path); | |
172 | |
124 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation | 173 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation |
125 //! fails. | 174 //! fails. |
126 //! | 175 //! |
127 //! \return On success, `true` is returned. On failure, an error is logged and | 176 //! \return On success, `true` is returned. On failure, an error is logged and |
128 //! `false` is returned. | 177 //! `false` is returned. |
129 bool LoggingCloseFile(FileHandle file); | 178 bool LoggingCloseFile(FileHandle file); |
130 | 179 |
131 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. | 180 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. |
132 //! | 181 //! |
133 //! If the underlying function fails, this function causes execution to | 182 //! If the underlying function fails, this function causes execution to |
134 //! terminate without returning. | 183 //! terminate without returning. |
135 void CheckedCloseFile(FileHandle file); | 184 void CheckedCloseFile(FileHandle file); |
136 | 185 |
137 } // namespace crashpad | 186 } // namespace crashpad |
138 | 187 |
139 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ | 188 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ |
OLD | NEW |