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_POSIX) |
23 #include "base/files/scoped_file.h" | |
24 #elif defined(OS_WIN) | |
23 #include <windows.h> | 25 #include <windows.h> |
26 #include "util/win/scoped_handle.h" | |
24 #endif | 27 #endif |
25 | 28 |
26 namespace base { | 29 namespace base { |
27 class FilePath; | 30 class FilePath; |
28 } // namespace base | 31 } // namespace base |
29 | 32 |
30 namespace crashpad { | 33 namespace crashpad { |
31 | 34 |
32 #if defined(OS_POSIX) || DOXYGEN | 35 #if defined(OS_POSIX) || DOXYGEN |
33 | 36 |
34 //! \brief Platform-specific alias for a low-level file handle. | 37 //! \brief Platform-specific alias for a low-level file handle. |
35 using FileHandle = int; | 38 using FileHandle = int; |
36 | 39 |
37 //! \brief Platform-specific alias for a position in an open file. | 40 //! \brief Platform-specific alias for a position in an open file. |
38 using FileOffset = off_t; | 41 using FileOffset = off_t; |
39 | 42 |
43 //! \brief Scoped wrapper of a FileHandle. | |
44 using ScopedFileHandle = base::ScopedFD; | |
Mark Mentovai
2014/12/19 20:42:57
Good thing this name is available. :)
scottmg
2014/12/19 21:32:41
You can see the future! :)
| |
45 | |
40 #elif defined(OS_WIN) | 46 #elif defined(OS_WIN) |
41 | 47 |
42 using FileHandle = HANDLE; | 48 using FileHandle = HANDLE; |
43 using FileOffset = LONGLONG; | 49 using FileOffset = LONGLONG; |
50 using ScopedFileHandle = ScopedFileHANDLE; | |
44 | 51 |
45 #endif | 52 #endif |
46 | 53 |
47 //! \brief Determines the mode that LoggingOpenFileForWrite() uses. | 54 //! \brief Determines the mode that LoggingOpenFileForWrite() uses. |
48 enum class FileWriteMode { | 55 enum class FileWriteMode { |
49 //! \brief Opens the file if it exists, or creates a new file. | 56 //! \brief Opens the file if it exists, or creates a new file. |
50 kReuseOrCreate, | 57 kReuseOrCreate, |
51 | 58 |
52 //! \brief Creates a new file. If the file already exists, it will be | 59 //! \brief Creates a new file. If the file already exists, it will be |
53 //! overwritten. | 60 //! overwritten. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 //! | 152 //! |
146 //! \sa CheckedReadFile | 153 //! \sa CheckedReadFile |
147 //! \sa ReadFile | 154 //! \sa ReadFile |
148 void CheckedReadFileAtEOF(FileHandle file); | 155 void CheckedReadFileAtEOF(FileHandle file); |
149 | 156 |
150 //! \brief Wraps `open()` or `CreateFile()`, opening an existing file for | 157 //! \brief Wraps `open()` or `CreateFile()`, opening an existing file for |
151 //! reading. Logs an error if the operation fails. | 158 //! reading. Logs an error if the operation fails. |
152 //! | 159 //! |
153 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. | 160 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. |
154 //! | 161 //! |
155 //! \sa ScopedFD | 162 //! \sa ScopedFD |
Mark Mentovai
2014/12/19 20:42:57
These two \sa can become one now, same for the ope
scottmg
2014/12/19 21:32:41
Done.
| |
156 //! \sa ScopedFileHANDLE | 163 //! \sa ScopedFileHANDLE |
157 FileHandle LoggingOpenFileForRead(const base::FilePath& path); | 164 FileHandle LoggingOpenFileForRead(const base::FilePath& path); |
158 | 165 |
159 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs | 166 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs |
160 //! an error if the operation fails. | 167 //! an error if the operation fails. |
161 //! | 168 //! |
162 //! \a write_mode determines the style (truncate, reuse, etc.) that is used to | 169 //! \a write_mode determines the style (truncate, reuse, etc.) that is used to |
163 //! open the file. On POSIX, if \a world_readable, `0644` will be used as | 170 //! open the file. On POSIX, if \a world_readable, `0644` will be used as |
164 //! `mode` permissions bits for `open()`, otherwise `0600` will be used. On | 171 //! `mode` permissions bits for `open()`, otherwise `0600` will be used. On |
165 //! Windows, the file is always opened in binary mode (that is, no CRLF | 172 //! Windows, the file is always opened in binary mode (that is, no CRLF |
(...skipping 28 matching lines...) Expand all Loading... | |
194 | 201 |
195 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. | 202 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. |
196 //! | 203 //! |
197 //! If the underlying function fails, this function causes execution to | 204 //! If the underlying function fails, this function causes execution to |
198 //! terminate without returning. | 205 //! terminate without returning. |
199 void CheckedCloseFile(FileHandle file); | 206 void CheckedCloseFile(FileHandle file); |
200 | 207 |
201 } // namespace crashpad | 208 } // namespace crashpad |
202 | 209 |
203 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ | 210 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ |
OLD | NEW |