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

Unified Diff: net/base/file_stream_win.cc

Issue 39301: Adds truncate to FileStream. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | « net/base/file_stream_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_win.cc
===================================================================
--- net/base/file_stream_win.cc (revision 11127)
+++ net/base/file_stream_win.cc (working copy)
@@ -287,4 +287,28 @@
return rv;
}
+int64 FileStream::Truncate(int64 bytes) {
+ if (!IsOpen())
+ return ERR_UNEXPECTED;
+
+ // We better be open for reading.
+ DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
+
+ // Seek to the position to truncate from.
+ int64 seek_position = Seek(FROM_BEGIN, bytes);
+ if (seek_position != bytes)
+ return ERR_UNEXPECTED;
+
+ // And truncate the file.
+ BOOL result = SetEndOfFile(file_);
+ if (!result) {
+ DWORD error = GetLastError();
+ LOG(WARNING) << "SetEndOfFile failed: " << error;
+ return MapErrorCode(error);
+ }
+
+ // Success.
+ return seek_position;
+}
+
} // namespace net
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698