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

Unified Diff: util/file/file_io_posix.cc

Issue 1390023002: Add FileWriteMode::kCreateOrFail (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Test that kReuseOrCreate can create 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.h ('k') | util/file/file_io_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_io_posix.cc
diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc
index 9511b34e7215df85d8a2eafea95c59f965beacfe..29cdfec5cafd205a24c8620567131980ac4b6b52 100644
--- a/util/file/file_io_posix.cc
+++ b/util/file/file_io_posix.cc
@@ -75,12 +75,22 @@ FileHandle LoggingOpenFileForOutput(int rdwr_or_wronly,
const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions) {
- int flags = rdwr_or_wronly | O_CREAT;
- // kReuseOrCreate does not need any additional flags.
- if (mode == FileWriteMode::kTruncateOrCreate)
- flags |= O_TRUNC;
- else if (mode == FileWriteMode::kCreateOrFail)
- flags |= O_EXCL;
+ int flags = rdwr_or_wronly & (O_RDWR | O_WRONLY);
+ DCHECK_NE(flags, 0);
+
+ switch (mode) {
+ case FileWriteMode::kReuseOrFail:
+ break;
+ case FileWriteMode::kReuseOrCreate:
+ flags |= O_CREAT;
+ break;
+ case FileWriteMode::kTruncateOrCreate:
+ flags |= O_CREAT | O_TRUNC;
+ break;
+ case FileWriteMode::kCreateOrFail:
+ flags |= O_CREAT | O_EXCL;
+ break;
+ }
int fd = HANDLE_EINTR(
open(path.value().c_str(),
« no previous file with comments | « util/file/file_io.h ('k') | util/file/file_io_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698