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

Unified Diff: util/file/file_io_posix.cc

Issue 818433002: Add LoggingOpenFileFor{Read|Write} (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@scoped-handle-land
Patch Set: . Created 6 years 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 ff32009021679f3690e9a7eb65c402dfc2e5f6d1..8681ad8dade067b8cbdd23cc1311730d167f04e0 100644
--- a/util/file/file_io_posix.cc
+++ b/util/file/file_io_posix.cc
@@ -14,8 +14,10 @@
#include "util/file/file_io.h"
+#include <fcntl.h>
#include <unistd.h>
+#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h"
@@ -74,6 +76,28 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) {
return ReadOrWrite<WriteTraits>(file, buffer, size);
}
+FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
+ int fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value();
+ return fd;
+}
+
+FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
+ FileWriteMode mode,
+ bool world_readable) {
+ 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;
+
+ int fd = HANDLE_EINTR(
+ open(path.value().c_str(), flags, world_readable ? 0644 : 0600));
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value();
+ return fd;
+}
+
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