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

Unified Diff: util/file/file_io_win.cc

Issue 1395543002: Add non-logging OpenFileForWrite() and OpenFileForReadAndWrite() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 months 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 | « util/file/file_io_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_io_win.cc
diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc
index dce1518aba89b1f0bdc617fe0a5569a99455b6a6..8b9da4557f4929878cdaf3c93f0d9f20c457305d 100644
--- a/util/file/file_io_win.cc
+++ b/util/file/file_io_win.cc
@@ -37,10 +37,13 @@ namespace crashpad {
namespace {
-FileHandle LoggingOpenFileForOutput(DWORD access,
- const base::FilePath& path,
- FileWriteMode mode,
- FilePermissions permissions) {
+FileHandle OpenFileForOutput(DWORD access,
+ const base::FilePath& path,
+ FileWriteMode mode,
+ FilePermissions permissions) {
+ DCHECK(access & GENERIC_WRITE);
+ DCHECK_EQ(access & ~(GENERIC_READ | GENERIC_WRITE), 0u);
+
DWORD disposition = 0;
switch (mode) {
case FileWriteMode::kReuseOrFail:
@@ -56,16 +59,13 @@ FileHandle LoggingOpenFileForOutput(DWORD access,
disposition = CREATE_NEW;
break;
}
- HANDLE file = CreateFile(path.value().c_str(),
- access,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- nullptr,
- disposition,
- FILE_ATTRIBUTE_NORMAL,
- nullptr);
- PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
- << "CreateFile " << base::UTF16ToUTF8(path.value());
- return file;
+ return CreateFile(path.value().c_str(),
+ access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ nullptr,
+ disposition,
+ FILE_ATTRIBUTE_NORMAL,
+ nullptr);
}
} // namespace
@@ -115,14 +115,31 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) {
return bytes_written;
}
+FileHandle OpenFileForRead(const base::FilePath& path) {
+ return CreateFile(path.value().c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ nullptr,
+ OPEN_EXISTING,
+ 0,
+ nullptr);
+}
+
+FileHandle OpenFileForWrite(const base::FilePath& path,
+ FileWriteMode mode,
+ FilePermissions permissions) {
+ return OpenFileForOutput(GENERIC_WRITE, path, mode, permissions);
+}
+
+FileHandle OpenFileForReadAndWrite(const base::FilePath& path,
+ FileWriteMode mode,
+ FilePermissions permissions) {
+ return OpenFileForOutput(
+ GENERIC_READ | GENERIC_WRITE, path, mode, permissions);
+}
+
FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
- HANDLE file = CreateFile(path.value().c_str(),
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- nullptr,
- OPEN_EXISTING,
- 0,
- nullptr);
+ FileHandle file = OpenFileForRead(path);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
<< "CreateFile " << base::UTF16ToUTF8(path.value());
return file;
@@ -131,14 +148,19 @@ FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions) {
- return LoggingOpenFileForOutput(GENERIC_WRITE, path, mode, permissions);
+ FileHandle file = OpenFileForWrite(path, mode, permissions);
+ PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
+ << "CreateFile " << base::UTF16ToUTF8(path.value());
+ return file;
}
FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions) {
- return LoggingOpenFileForOutput(
- GENERIC_READ | GENERIC_WRITE, path, mode, permissions);
+ FileHandle file = OpenFileForReadAndWrite(path, mode, permissions);
+ PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE)
+ << "CreateFile " << base::UTF16ToUTF8(path.value());
+ return file;
}
bool LoggingLockFile(FileHandle file, FileLocking locking) {
« no previous file with comments | « util/file/file_io_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698