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

Unified Diff: util/file/file_io_win.cc

Issue 818433002: Add LoggingOpenFileFor{Read|Write} (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@scoped-handle-land
Patch Set: . 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 | « util/file/file_io_posix.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 b1640dd0424759be13168bef86f7beb1627d9747..7426737dcfe9cdaf82e5601ccd1e5f9d97af67d8 100644
--- a/util/file/file_io_win.cc
+++ b/util/file/file_io_win.cc
@@ -14,6 +14,7 @@
#include "util/file/file_io.h"
+#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
@@ -72,6 +73,36 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) {
return bytes_written;
}
+FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
+ HANDLE file = CreateFile(path.value().c_str(), GENERIC_READ, FILE_SHARE_READ,
+ nullptr, OPEN_EXISTING, 0, nullptr);
+ PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
+ << path.value().c_str();
+ return file;
+}
+
+FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
+ FileWriteMode mode,
+ bool world_readable) {
+ DWORD disposition = 0;
+ switch (mode) {
+ case FileWriteMode::kReuseOrCreate:
+ disposition = OPEN_ALWAYS;
+ break;
+ case FileWriteMode::kTruncateOrCreate:
+ disposition = CREATE_ALWAYS;
+ break;
+ case FileWriteMode::kCreateOrFail:
+ disposition = CREATE_NEW;
+ break;
+ }
+ HANDLE file = CreateFile(path.value().c_str(), GENERIC_WRITE, 0, nullptr,
+ disposition, FILE_ATTRIBUTE_NORMAL, nullptr);
+ PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
+ << path.value().c_str();
+ return file;
+}
+
bool LoggingCloseFile(FileHandle file) {
BOOL rv = CloseHandle(file);
PLOG_IF(ERROR, !rv) << "CloseHandle";
« no previous file with comments | « util/file/file_io_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698