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

Unified Diff: util/file/file_io_posix.cc

Issue 1395543002: Add non-logging OpenFileForWrite() and OpenFileForReadAndWrite() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: 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 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) {
« 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