OLD | NEW |
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 Loading... |
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 |
OLD | NEW |