summaryrefslogtreecommitdiffstats
path: root/net/base/file_stream_posix.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 15:49:20 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 15:49:20 +0000
commit0643a49e311c0ddb17f292f525ebd11f51f158a1 (patch)
treede8f50c0070fd6ff52eced3bdd96c747f1e9ea45 /net/base/file_stream_posix.cc
parentf3e8965444b0b615ed8aabfcacc5840f6684c0c5 (diff)
downloadchromium_src-0643a49e311c0ddb17f292f525ebd11f51f158a1.zip
chromium_src-0643a49e311c0ddb17f292f525ebd11f51f158a1.tar.gz
chromium_src-0643a49e311c0ddb17f292f525ebd11f51f158a1.tar.bz2
Adds truncate to FileStream.
BUG=none TEST=none Review URL: http://codereview.chromium.org/39301 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/file_stream_posix.cc')
-rw-r--r--net/base/file_stream_posix.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index 34f7889..d7f4811 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -201,4 +201,21 @@ int FileStream::Write(
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