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

Unified Diff: util/file/file_io_posix.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.h ('k') | util/file/file_io_win.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 a1f3b5d16820523a22ee563bb40a0c33a4edb4a3..9511b34e7215df85d8a2eafea95c59f965beacfe 100644
--- a/util/file/file_io_posix.cc
+++ b/util/file/file_io_posix.cc
@@ -69,6 +69,29 @@ ssize_t ReadOrWrite(int fd,
namespace crashpad {
+namespace {
+
+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 fd = HANDLE_EINTR(
+ open(path.value().c_str(),
+ flags,
+ permissions == FilePermissions::kWorldReadable ? 0644 : 0600));
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value();
+ return fd;
+}
+
+} // namespace
+
ssize_t ReadFile(FileHandle file, void* buffer, size_t size) {
return ReadOrWrite<ReadTraits>(file, buffer, size);
}
@@ -86,19 +109,13 @@ FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions) {
- int flags = O_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;
+ return LoggingOpenFileForOutput(O_WRONLY, path, mode, permissions);
+}
- int fd = HANDLE_EINTR(
- open(path.value().c_str(),
- flags,
- permissions == FilePermissions::kWorldReadable ? 0644 : 0600));
- 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);
}
bool LoggingLockFile(FileHandle file, FileLocking locking) {
@@ -120,6 +137,14 @@ FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
return rv;
}
+bool LoggingTruncateFile(FileHandle file) {
+ if (HANDLE_EINTR(ftruncate(file, 0)) != 0) {
+ PLOG(ERROR) << "ftruncate";
+ return false;
+ }
+ return true;
+}
+
bool LoggingCloseFile(FileHandle file) {
int rv = IGNORE_EINTR(close(file));
PLOG_IF(ERROR, rv != 0) << "close";
« no previous file with comments | « util/file/file_io.h ('k') | util/file/file_io_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698