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

Unified Diff: base/platform_file_posix.cc

Issue 15861011: Add an "append flag" to base::PlatformFile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ignore write offset when PLATFORM_FILE_APPEND. Created 7 years, 6 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 | « base/platform_file.h ('k') | base/platform_file_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_file_posix.cc
diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc
index beae804c629c86a6b8fa4ef716f601552d9a114e..40c0d81fca720d8702797431acbc133cc3ac3e8b 100644
--- a/base/platform_file_posix.cc
+++ b/base/platform_file_posix.cc
@@ -81,6 +81,7 @@ PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
open_flags |= O_WRONLY;
} else if (!(flags & PLATFORM_FILE_READ) &&
!(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) &&
+ !(flags & PLATFORM_FILE_APPEND) &&
!(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
NOTREACHED();
}
@@ -88,6 +89,11 @@ PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
if (flags & PLATFORM_FILE_TERMINAL_DEVICE)
open_flags |= O_NOCTTY | O_NDELAY;
+ if (flags & PLATFORM_FILE_APPEND && flags & PLATFORM_FILE_READ)
+ open_flags |= O_APPEND | O_RDWR;
+ else if (flags & PLATFORM_FILE_APPEND)
+ open_flags |= O_APPEND | O_WRONLY;
+
COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
int mode = S_IRUSR | S_IWUSR;
@@ -207,6 +213,10 @@ int ReadPlatformFileCurPosNoBestEffort(PlatformFile file,
int WritePlatformFile(PlatformFile file, int64 offset,
const char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
+
+ if (fcntl(file, F_GETFL) & O_APPEND)
+ return WritePlatformFileAtCurrentPos(file, data, size);
+
if (file < 0 || size < 0)
return -1;
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698