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

Unified Diff: util/file/file_io_win.cc

Issue 999953002: Use LockFile/UnlockFile for Settings to port to Windows (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@lock-fileio-2
Patch Set: Tag inside, no info spam Created 5 years, 8 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_posix.cc ('k') | util/misc/uuid.h » ('j') | 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 33da8baa36bec4539f3c99a7e493f83d74fb04c7..0f7476d0a5007d4bb71b7ae00c29e7ac5ba0061a 100644
--- a/util/file/file_io_win.cc
+++ b/util/file/file_io_win.cc
@@ -34,6 +34,38 @@ bool IsSocketHandle(HANDLE file) {
namespace crashpad {
+namespace {
+
+FileHandle LoggingOpenFileForOutput(DWORD access,
+ const base::FilePath& path,
+ FileWriteMode mode,
+ FilePermissions permissions) {
+ 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(),
+ access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ nullptr,
+ disposition,
+ FILE_ATTRIBUTE_NORMAL,
+ nullptr);
+ PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
+ << path.value().c_str();
+ return file;
+}
+
+} // namespace
+
// TODO(scottmg): Handle > DWORD sized writes if necessary.
ssize_t ReadFile(FileHandle file, void* buffer, size_t size) {
@@ -95,28 +127,14 @@ FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions) {
- 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,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- nullptr,
- disposition,
- FILE_ATTRIBUTE_NORMAL,
- nullptr);
- PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
- << path.value().c_str();
- return file;
+ return LoggingOpenFileForOutput(GENERIC_WRITE, path, mode, permissions);
+}
+
+FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path,
+ FileWriteMode mode,
+ FilePermissions permissions) {
+ return LoggingOpenFileForOutput(
+ GENERIC_READ | GENERIC_WRITE, path, mode, permissions);
}
bool LoggingLockFile(FileHandle file, FileLocking locking) {
@@ -174,6 +192,16 @@ FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
return new_offset.QuadPart;
}
+bool LoggingTruncateFile(FileHandle file) {
+ if (LoggingSeekFile(file, 0, SEEK_SET) != 0)
+ return false;
+ if (!SetEndOfFile(file)) {
+ PLOG(ERROR) << "SetEndOfFile";
+ return false;
+ }
+ return true;
+}
+
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') | util/misc/uuid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698