| 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 12 matching lines...) Expand all Loading... |
| 23 #include <windows.h> | 23 #include <windows.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class FilePath; | 27 class FilePath; |
| 28 } // namespace base | 28 } // namespace base |
| 29 | 29 |
| 30 namespace crashpad { | 30 namespace crashpad { |
| 31 | 31 |
| 32 #if defined(OS_POSIX) || DOXYGEN | 32 #if defined(OS_POSIX) || DOXYGEN |
| 33 |
| 33 //! \brief Platform-specific alias for a low-level file handle. | 34 //! \brief Platform-specific alias for a low-level file handle. |
| 34 using FileHandle = int; | 35 using FileHandle = int; |
| 36 |
| 37 //! \brief Platform-specific alias for a position in an open file. |
| 38 using FileOffset = off_t; |
| 39 |
| 35 #elif defined(OS_WIN) | 40 #elif defined(OS_WIN) |
| 41 |
| 36 using FileHandle = HANDLE; | 42 using FileHandle = HANDLE; |
| 43 using FileOffset = LONGLONG; |
| 44 |
| 37 #endif | 45 #endif |
| 38 | 46 |
| 39 //! \brief Determines the mode that LoggingOpenFileForWrite() uses. | 47 //! \brief Determines the mode that LoggingOpenFileForWrite() uses. |
| 40 enum class FileWriteMode { | 48 enum class FileWriteMode { |
| 41 //! \brief Opens the file if it exists, or creates a new file. | 49 //! \brief Opens the file if it exists, or creates a new file. |
| 42 kReuseOrCreate, | 50 kReuseOrCreate, |
| 43 | 51 |
| 44 //! \brief Creates a new file. If the file already exists, it will be | 52 //! \brief Creates a new file. If the file already exists, it will be |
| 45 //! overwritten. | 53 //! overwritten. |
| 46 kTruncateOrCreate, | 54 kTruncateOrCreate, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 //! | 167 //! |
| 160 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. | 168 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. |
| 161 //! | 169 //! |
| 162 //! \sa FileWriteMode | 170 //! \sa FileWriteMode |
| 163 //! \sa ScopedFD | 171 //! \sa ScopedFD |
| 164 //! \sa ScopedFileHANDLE | 172 //! \sa ScopedFileHANDLE |
| 165 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, | 173 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
| 166 FileWriteMode write_mode, | 174 FileWriteMode write_mode, |
| 167 bool world_readable); | 175 bool world_readable); |
| 168 | 176 |
| 177 //! \brief Wraps `lseek()` or `SetFilePointerEx()`. Logs an error if the |
| 178 //! operation fails. |
| 179 //! |
| 180 //! 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 |
| 182 //! `SEEK_END`, and is interpreted in the usual way. |
| 183 //! |
| 184 //! \return The resulting offset in bytes from the beginning of the file, or |
| 185 //! `-1` on failure. |
| 186 FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence); |
| 187 |
| 169 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation | 188 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation |
| 170 //! fails. | 189 //! fails. |
| 171 //! | 190 //! |
| 172 //! \return On success, `true` is returned. On failure, an error is logged and | 191 //! \return On success, `true` is returned. On failure, an error is logged and |
| 173 //! `false` is returned. | 192 //! `false` is returned. |
| 174 bool LoggingCloseFile(FileHandle file); | 193 bool LoggingCloseFile(FileHandle file); |
| 175 | 194 |
| 176 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. | 195 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. |
| 177 //! | 196 //! |
| 178 //! If the underlying function fails, this function causes execution to | 197 //! If the underlying function fails, this function causes execution to |
| 179 //! terminate without returning. | 198 //! terminate without returning. |
| 180 void CheckedCloseFile(FileHandle file); | 199 void CheckedCloseFile(FileHandle file); |
| 181 | 200 |
| 182 } // namespace crashpad | 201 } // namespace crashpad |
| 183 | 202 |
| 184 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ | 203 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ |
| OLD | NEW |