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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 } else if (overlapped) { 281 } else if (overlapped) {
282 async_context_->IOCompletionIsPending(callback); 282 async_context_->IOCompletionIsPending(callback);
283 rv = ERR_IO_PENDING; 283 rv = ERR_IO_PENDING;
284 } else { 284 } else {
285 rv = static_cast<int>(bytes_written); 285 rv = static_cast<int>(bytes_written);
286 } 286 }
287 return rv; 287 return rv;
288 } 288 }
289 289
290 int64 FileStream::Truncate(int64 bytes) {
291 if (!IsOpen())
292 return ERR_UNEXPECTED;
293
294 // We better be open for reading.
295 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
296
297 // Seek to the position to truncate from.
298 int64 seek_position = Seek(FROM_BEGIN, bytes);
299 if (seek_position != bytes)
300 return ERR_UNEXPECTED;
301
302 // And truncate the file.
303 BOOL result = SetEndOfFile(file_);
304 if (!result) {
305 DWORD error = GetLastError();
306 LOG(WARNING) << "SetEndOfFile failed: " << error;
307 return MapErrorCode(error);
308 }
309
310 // Success.
311 return seek_position;
312 }
313
290 } // namespace net 314 } // namespace net
OLDNEW
« 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