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 |