Index: util/file/file_io.h |
diff --git a/util/file/file_io.h b/util/file/file_io.h |
index 927bc3cb13319ff5843a613cff77bbfd20588648..8c6486df0b8ffa10c1a7d82f98660871c6032a34 100644 |
--- a/util/file/file_io.h |
+++ b/util/file/file_io.h |
@@ -23,14 +23,32 @@ |
#include <windows.h> |
#endif |
+namespace base { |
+class FilePath; |
+} // namespace base |
+ |
namespace crashpad { |
-#if defined(OS_POSIX) |
+#if defined(OS_POSIX) || DOXYGEN |
+//! \brief Platform-specific alias for a low level file handle. |
using FileHandle = int; |
#elif defined(OS_WIN) |
using FileHandle = HANDLE; |
#endif |
+//! \brief Determines the mode that LoggingOpenFileForWrite() uses. |
+enum class FileWriteMode { |
+ //! \brief Opens the file if it exists, or creates a new file. |
+ kAppend, |
Mark Mentovai
2014/12/18 21:52:32
kAppend still sounds like it seeks to the end…
Ho
scottmg
2014/12/18 22:12:44
"Reuse" sounds a bit funny to me, but I can't thin
|
+ |
+ //! \brief Creates a new file. If the file already exists, it will be |
+ //! overwritten. |
+ kCreate, |
+ |
+ //! \brief Creates a new file. If the file already exists, the open will fail. |
+ kCreateNew, |
+}; |
+ |
//! \brief Reads from a file, retrying when interrupted on POSIX or following a |
//! short read. |
//! |
@@ -121,6 +139,33 @@ void CheckedWriteFile(FileHandle file, const void* buffer, size_t size); |
//! \sa ReadFile |
void CheckedReadFileAtEOF(FileHandle file); |
+//! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs |
+//! an error if the operation fails. |
+//! |
+//! \a write_mode determines the style (clobber, truncate, etc.) that is used |
Mark Mentovai
2014/12/18 21:52:32
clobber == truncate, right?
scottmg
2014/12/18 22:12:44
Done.
|
+//! to open the file. On POSIX, if \a world_readable, `0644` will be used as |
+//! `mode` permissions bits for `open()`, otherwise `0600` will be used. On |
Mark Mentovai
2014/12/18 21:52:32
Yup, score!
|
+//! Windows, the file is always opened in binary mode (that is, no CRLF |
+//! translation). |
+//! |
+//! \return The newly opened FileHandle, or an invalid FileHandle on failure. |
+//! |
+//! \sa FileWriteMode |
+//! \sa ScopedFD |
+//! \sa ScopedFileHANDLE |
+FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
+ FileWriteMode write_mode, |
+ bool world_readable); |
+ |
+//! \brief Wraps `open()` or `CreateFile()`, opening an existing file for |
+//! reading. Logs an error if the operation fails. |
+//! |
+//! \return The newly opened FileHandle, or an invalid FileHandle on failure. |
+//! |
+//! \sa ScopedFD |
+//! \sa ScopedFileHANDLE |
+FileHandle LoggingOpenFileForRead(const base::FilePath& path); |
+ |
//! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation |
//! fails. |
//! |