Index: base/file_util_win.cc |
diff --git a/base/file_util_win.cc b/base/file_util_win.cc |
index 7d28f5cf637602da245dcbfed5477c9108fe5954..e9f9defa8797be949e2854b05dac76fcafcd5b54 100644 |
--- a/base/file_util_win.cc |
+++ b/base/file_util_win.cc |
@@ -722,6 +722,38 @@ int WriteFile(const FilePath& filename, const char* data, int size) { |
return -1; |
} |
+int AppendToFile(const FilePath& filename, const char* data, int size) { |
+ base::ThreadRestrictions::AssertIOAllowed(); |
+ base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
+ FILE_APPEND_DATA, |
+ 0, |
+ NULL, |
+ OPEN_EXISTING, |
+ 0, |
+ NULL)); |
+ if (!file) { |
+ DLOG(WARNING) << "CreateFile failed for path " << filename.value() |
+ << " error code=" << GetLastError(); |
+ return -1; |
+ } |
+ |
+ DWORD written; |
+ BOOL result = ::WriteFile(file, data, size, &written, NULL); |
+ if (result && static_cast<int>(written) == size) |
+ return written; |
+ |
+ if (!result) { |
+ // WriteFile failed. |
+ DLOG(WARNING) << "writing file " << filename.value() |
+ << " failed, error code=" << GetLastError(); |
+ } else { |
+ // Didn't write all the bytes. |
+ DLOG(WARNING) << "wrote" << written << " bytes to " |
+ << filename.value() << " expected " << size; |
+ } |
+ return -1; |
+} |
+ |
// Gets the current working directory for the process. |
bool GetCurrentDirectory(FilePath* dir) { |
base::ThreadRestrictions::AssertIOAllowed(); |