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

Unified Diff: net/base/file_stream_posix.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.h ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_posix.cc
===================================================================
--- net/base/file_stream_posix.cc (revision 11127)
+++ net/base/file_stream_posix.cc (working copy)
@@ -201,4 +201,21 @@
return total_bytes_written;
}
+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.
+ int result = ftruncate(file_, bytes);
+ return result == 0 ? seek_position : MapErrorCode(errno);
+}
+
} // namespace net
« no previous file with comments | « net/base/file_stream.h ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698