Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: util/file/file_io.h

Issue 818433002: Add LoggingOpenFileFor{Read|Write} (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@scoped-handle-land
Patch Set: mode Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | util/file/file_io_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_io.h
diff --git a/util/file/file_io.h b/util/file/file_io.h
index 927bc3cb13319ff5843a613cff77bbfd20588648..571d5d0024f14ba8f8bd1bad3eaf9e7f7b9ae93e 100644
--- a/util/file/file_io.h
+++ b/util/file/file_io.h
@@ -23,14 +23,37 @@
#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.
Mark Mentovai 2014/12/18 20:24:59 () on function names.
scottmg 2014/12/18 21:18:54 Done.
+enum FileWriteMode {
+ //! \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
+ //! creates a new file.
+ kAppend,
+
+ //! \brief Creates a new file. If the file already exists, it will be
+ //! 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:
+ kCreate,
+
+ //! \brief Creates a new file. If the file already exists, the open will fail.
+ kCreateNew,
+
+ //! \brief Opens an existing file. When the file is opened, it will be
+ //! truncated so that its size is zero bytes.
+ 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
+};
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
+
//! \brief Reads from a file, retrying when interrupted on POSIX or following a
//! short read.
//!
@@ -121,6 +144,32 @@ 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 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:
+//! to open the file. On POSIX, if \a world_readable, the permissions bits will
+//! 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.
+//! 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.
//!
« no previous file with comments | « no previous file | util/file/file_io_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698