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(), |