Index: util/file/file_io_posix.cc |
diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc |
index 29cdfec5cafd205a24c8620567131980ac4b6b52..c0969dcfcdb5e135f30dc87e7c1b16f557d73fa0 100644 |
--- a/util/file/file_io_posix.cc |
+++ b/util/file/file_io_posix.cc |
@@ -71,12 +71,14 @@ namespace crashpad { |
namespace { |
-FileHandle LoggingOpenFileForOutput(int rdwr_or_wronly, |
- const base::FilePath& path, |
- FileWriteMode mode, |
- FilePermissions permissions) { |
- int flags = rdwr_or_wronly & (O_RDWR | O_WRONLY); |
- DCHECK_NE(flags, 0); |
+FileHandle OpenFileForOutput(int rdwr_or_wronly, |
+ const base::FilePath& path, |
+ FileWriteMode mode, |
+ FilePermissions permissions) { |
+ DCHECK(rdwr_or_wronly & (O_RDWR | O_WRONLY)); |
+ DCHECK_EQ(rdwr_or_wronly & ~(O_RDWR | O_WRONLY), 0); |
+ |
+ int flags = rdwr_or_wronly; |
switch (mode) { |
case FileWriteMode::kReuseOrFail: |
@@ -92,12 +94,10 @@ FileHandle LoggingOpenFileForOutput(int rdwr_or_wronly, |
break; |
} |
- int fd = HANDLE_EINTR( |
+ return HANDLE_EINTR( |
open(path.value().c_str(), |
flags, |
permissions == FilePermissions::kWorldReadable ? 0644 : 0600)); |
- PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
- return fd; |
} |
} // namespace |
@@ -110,8 +110,24 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) { |
return ReadOrWrite<WriteTraits>(file, buffer, size); |
} |
+FileHandle OpenFileForRead(const base::FilePath& path) { |
+ return HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)); |
+} |
+ |
+FileHandle OpenFileForWrite(const base::FilePath& path, |
+ FileWriteMode mode, |
+ FilePermissions permissions) { |
+ return OpenFileForOutput(O_WRONLY, path, mode, permissions); |
+} |
+ |
+FileHandle OpenFileForReadAndWrite(const base::FilePath& path, |
+ FileWriteMode mode, |
+ FilePermissions permissions) { |
+ return OpenFileForOutput(O_RDWR, path, mode, permissions); |
+} |
+ |
FileHandle LoggingOpenFileForRead(const base::FilePath& path) { |
- int fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)); |
+ FileHandle fd = OpenFileForRead(path); |
PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
return fd; |
} |
@@ -119,13 +135,17 @@ FileHandle LoggingOpenFileForRead(const base::FilePath& path) { |
FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
FileWriteMode mode, |
FilePermissions permissions) { |
- return LoggingOpenFileForOutput(O_WRONLY, path, mode, permissions); |
+ FileHandle fd = OpenFileForWrite(path, mode, permissions); |
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
+ return fd; |
} |
FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path, |
FileWriteMode mode, |
FilePermissions permissions) { |
- return LoggingOpenFileForOutput(O_RDWR, path, mode, permissions); |
+ FileHandle fd = OpenFileForReadAndWrite(path, mode, permissions); |
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
+ return fd; |
} |
bool LoggingLockFile(FileHandle file, FileLocking locking) { |