| 564 | } |
| 565 | |
| 566 | void CheckedFile::extend( uint64_t newLength, OffsetMode omode ) |
| 567 | { |
| 568 | #ifdef E57_VERBOSE |
| 569 | // cout << "extend newLength=" << newLength << " omode="<< omode << std::endl; |
| 570 | // //??? |
| 571 | #endif |
| 572 | if ( readOnly_ ) |
| 573 | { |
| 574 | throw E57_EXCEPTION2( ErrorFileReadOnly, "fileName=" + fileName_ ); |
| 575 | } |
| 576 | |
| 577 | uint64_t newLogicalLength = 0; |
| 578 | |
| 579 | if ( omode == Physical ) |
| 580 | { |
| 581 | newLogicalLength = physicalToLogical( newLength ); |
| 582 | } |
| 583 | else |
| 584 | { |
| 585 | newLogicalLength = newLength; |
| 586 | } |
| 587 | |
| 588 | uint64_t currentLogicalLength = length( Logical ); |
| 589 | |
| 590 | // Make sure we are trying to make file longer |
| 591 | if ( newLogicalLength < currentLogicalLength ) |
| 592 | { |
| 593 | throw E57_EXCEPTION2( ErrorInternal, |
| 594 | "fileName=" + fileName_ + " newLength=" + toString( newLogicalLength ) + |
| 595 | " currentLength=" + toString( currentLogicalLength ) ); |
| 596 | } |
| 597 | |
| 598 | // Calc how may zero bytes we have to add to end |
| 599 | uint64_t nWrite = newLogicalLength - currentLogicalLength; |
| 600 | |
| 601 | // Seek to current end of file |
| 602 | seek( currentLogicalLength, Logical ); |
| 603 | |
| 604 | uint64_t page = 0; |
| 605 | size_t pageOffset = 0; |
| 606 | |
| 607 | getCurrentPageAndOffset( page, pageOffset ); |
| 608 | |
| 609 | // Calc first write size (may be partial page) |
| 610 | // Watch out for different int sizes here. |
| 611 | size_t n = 0; |
| 612 | |
| 613 | if ( nWrite < logicalPageSize - pageOffset ) |
| 614 | { |
| 615 | n = static_cast<size_t>( nWrite ); |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | n = logicalPageSize - pageOffset; |
| 620 | } |
| 621 | |
| 622 | // Allocate temp page buffer |
| 623 | std::vector<char> page_buffer_v( physicalPageSize ); |
no test coverage detected