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..e8dbe9aab4a9e1f89ed491639182fad29f4fcbde 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,33 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) { |
return ReadOrWrite<WriteTraits>(file, buffer, size); |
} |
+FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
+ FileWriteMode mode, |
+ bool world_readable) { |
+ int flags = O_WRONLY; |
Mark Mentovai
2014/12/18 21:52:32
This should be O_WRONLY | O_CREAT, because we alwa
scottmg
2014/12/18 22:12:44
Done.
|
+ switch (mode) { |
+ case FileWriteMode::kAppend: |
+ // Nothing to add. |
+ break; |
+ case FileWriteMode::kCreate: |
+ flags |= O_CREAT | O_TRUNC; |
+ break; |
+ case FileWriteMode::kCreateNew: |
+ flags |= O_CREAT | O_EXCL; |
+ break; |
+ } |
+ int fd = HANDLE_EINTR( |
+ open(path.value().c_str(), flags, world_readable ? 0644 : 0600)); |
+ PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
+ return fd; |
+} |
+ |
+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; |
+} |
+ |
bool LoggingCloseFile(FileHandle file) { |
int rv = IGNORE_EINTR(close(file)); |
PLOG_IF(ERROR, rv != 0) << "close"; |