OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // For 64-bit file access (off_t = off64_t, lseek64, etc). | 5 // For 64-bit file access (off_t = off64_t, lseek64, etc). |
6 #define _FILE_OFFSET_BITS 64 | 6 #define _FILE_OFFSET_BITS 64 |
7 | 7 |
8 #include "net/base/file_stream.h" | 8 #include "net/base/file_stream.h" |
9 | 9 |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); | 447 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); |
448 // If we're in async, make sure we don't have a request in flight. | 448 // If we're in async, make sure we don't have a request in flight. |
449 DCHECK(!async_context_->callback()); | 449 DCHECK(!async_context_->callback()); |
450 async_context_->InitiateAsyncWrite(file_, buf, buf_len, callback); | 450 async_context_->InitiateAsyncWrite(file_, buf, buf_len, callback); |
451 return ERR_IO_PENDING; | 451 return ERR_IO_PENDING; |
452 } else { | 452 } else { |
453 return WriteFile(file_, buf, buf_len); | 453 return WriteFile(file_, buf, buf_len); |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 int FileStream::Flush() { | |
458 if (!IsOpen()) | |
459 return ERR_UNEXPECTED; | |
460 | |
461 return FlushFile(file_); | |
462 } | |
463 | |
464 int64 FileStream::Truncate(int64 bytes) { | 457 int64 FileStream::Truncate(int64 bytes) { |
465 if (!IsOpen()) | 458 if (!IsOpen()) |
466 return ERR_UNEXPECTED; | 459 return ERR_UNEXPECTED; |
467 | 460 |
468 // We better be open for reading. | 461 // We better be open for reading. |
469 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); | 462 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); |
470 | 463 |
471 // Seek to the position to truncate from. | 464 // Seek to the position to truncate from. |
472 int64 seek_position = Seek(FROM_BEGIN, bytes); | 465 int64 seek_position = Seek(FROM_BEGIN, bytes); |
473 if (seek_position != bytes) | 466 if (seek_position != bytes) |
474 return ERR_UNEXPECTED; | 467 return ERR_UNEXPECTED; |
475 | 468 |
476 // And truncate the file. | 469 // And truncate the file. |
477 int result = ftruncate(file_, bytes); | 470 int result = ftruncate(file_, bytes); |
478 return result == 0 ? seek_position : MapErrorCode(errno); | 471 return result == 0 ? seek_position : MapErrorCode(errno); |
479 } | 472 } |
480 | 473 |
| 474 int FileStream::Flush() { |
| 475 if (!IsOpen()) |
| 476 return ERR_UNEXPECTED; |
| 477 |
| 478 return FlushFile(file_); |
| 479 } |
| 480 |
481 } // namespace net | 481 } // namespace net |
OLD | NEW |