Index: osl/unx/file.cxx =================================================================== --- osl/unx/file.cxx (revision 276042) +++ osl/unx/file.cxx (working copy) @@ -110,6 +110,7 @@ oslFileError setPos (sal_uInt64 uPos); sal_uInt64 getSize() const; + void setSize( sal_uInt64 nSize ); oslFileError readAt ( off_t nOffset, @@ -271,6 +272,23 @@ return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend)); } +void FileHandle_Impl::setSize( sal_uInt64 nSize ) +{ + if ( nSize < sal::static_int_cast< sal_uInt64 >( m_bufptr ) ) + { + m_bufptr = 0; + m_buflen = 0; + } + else + { + off_t const bufend = std::max((off_t)(0), m_bufptr) + m_buflen; + if ( nSize < sal::static_int_cast< sal_uInt64 >( bufend ) ) + m_buflen = sal::static_int_cast< off_t >( nSize - sal::static_int_cast< sal_uInt64 >( m_bufptr ) ); + } + + m_size = nSize; +} + oslFileError FileHandle_Impl::readAt ( off_t nOffset, void * pBuffer, @@ -1338,6 +1356,7 @@ } OSL_FILE_TRACE("osl_setFileSize(%d, %lld) => %ld", pImpl->m_fd, pImpl->getSize(), nSize); - pImpl->m_size = sal::static_int_cast< sal_uInt64 >(nSize); + pImpl->setSize( uSize ); + return osl_File_E_None; } Index: osl/w32/file.cxx =================================================================== --- osl/w32/file.cxx (revision 276042) +++ osl/w32/file.cxx (working copy) @@ -103,6 +103,7 @@ oslFileError setPos (sal_uInt64 uPos); sal_uInt64 getSize() const; + void setSize( sal_uInt64 ); oslFileError readAt ( LONGLONG nOffset, @@ -253,6 +254,24 @@ return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend)); } +void FileHandle_Impl::setSize( sal_uInt64 nSize ) +{ + if ( nSize < sal::static_int_cast< sal_uInt64 >( m_bufptr ) ) + { + m_bufptr = 0; + m_buflen = 0; + } + else + { + LONGLONG const bufend = std::max((LONGLONG)(0), m_bufptr) + m_buflen; + if ( nSize < sal::static_int_cast< sal_uInt64 >( bufend ) ) + m_buflen = sal::static_int_cast< SIZE_T >( nSize - sal::static_int_cast< sal_uInt64 >( m_bufptr ) ); + } + + m_size = nSize; +} + + oslFileError FileHandle_Impl::readAt ( LONGLONG nOffset, void * pBuffer, @@ -1056,7 +1075,7 @@ if (!::SetEndOfFile(pImpl->m_hFile)) return oslTranslateFileError( GetLastError() ); - pImpl->m_size = uSize; + pImpl->setSize( uSize ); nDstPos.QuadPart = pImpl->m_offset; if (!::SetFilePointerEx(pImpl->m_hFile, nDstPos, 0, FILE_BEGIN))