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

Unified Diff: base/file_util_win.cc

Issue 10263003: AppendToFile implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698