| 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; |
| 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 ScopedFileHandle |
| 156 //! \sa ScopedFileHANDLE | |
| 157 FileHandle LoggingOpenFileForRead(const base::FilePath& path); | 163 FileHandle LoggingOpenFileForRead(const base::FilePath& path); |
| 158 | 164 |
| 159 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs | 165 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs |
| 160 //! an error if the operation fails. | 166 //! an error if the operation fails. |
| 161 //! | 167 //! |
| 162 //! \a write_mode determines the style (truncate, reuse, etc.) that is used to | 168 //! \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 | 169 //! 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 | 170 //! `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 | 171 //! Windows, the file is always opened in binary mode (that is, no CRLF |
| 166 //! translation). | 172 //! translation). |
| 167 //! | 173 //! |
| 168 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. | 174 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. |
| 169 //! | 175 //! |
| 170 //! \sa FileWriteMode | 176 //! \sa FileWriteMode |
| 171 //! \sa ScopedFD | 177 //! \sa ScopedFileHandle |
| 172 //! \sa ScopedFileHANDLE | |
| 173 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, | 178 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
| 174 FileWriteMode write_mode, | 179 FileWriteMode write_mode, |
| 175 bool world_readable); | 180 bool world_readable); |
| 176 | 181 |
| 177 //! \brief Wraps `lseek()` or `SetFilePointerEx()`. Logs an error if the | 182 //! \brief Wraps `lseek()` or `SetFilePointerEx()`. Logs an error if the |
| 178 //! operation fails. | 183 //! operation fails. |
| 179 //! | 184 //! |
| 180 //! Repositions the offset of the open \a file to the specified \a offset, | 185 //! Repositions the offset of the open \a file to the specified \a offset, |
| 181 //! relative to \a whence. \a whence must be one of `SEEK_SET`, `SEEK_CUR`, or | 186 //! relative to \a whence. \a whence must be one of `SEEK_SET`, `SEEK_CUR`, or |
| 182 //! `SEEK_END`, and is interpreted in the usual way. | 187 //! `SEEK_END`, and is interpreted in the usual way. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 | 199 |
| 195 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. | 200 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. |
| 196 //! | 201 //! |
| 197 //! If the underlying function fails, this function causes execution to | 202 //! If the underlying function fails, this function causes execution to |
| 198 //! terminate without returning. | 203 //! terminate without returning. |
| 199 void CheckedCloseFile(FileHandle file); | 204 void CheckedCloseFile(FileHandle file); |
| 200 | 205 |
| 201 } // namespace crashpad | 206 } // namespace crashpad |
| 202 | 207 |
| 203 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ | 208 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ |
| OLD | NEW |