include/tools/stream.hxx | 5 ++--- tools/source/stream/strmunx.cxx | 34 +++++++++++----------------------- tools/source/stream/strmwnt.cxx | 38 +++++++++++++------------------------- 3 files changed, 26 insertions(+), 51 deletions(-)
New commits: commit 6db64ffb8430d40475721662c77bbc18ac6255fb Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Feb 27 09:35:07 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Feb 27 11:34:07 2023 +0000 inline StreamData into SvFileStream Change-Id: Ib2bfaa903b5c57b7d802afe7928720e6007d54ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147865 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index b141c8ed44f7..4a5f91043021 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -587,12 +587,11 @@ TOOLS_DLLPUBLIC bool isEmptyFileUrl(const OUString& rUrl); class TOOLS_DLLPUBLIC SvFileStream final : public SvStream { private: - std::unique_ptr<StreamData> - pInstanceData; - OUString aFilename; + void* mxFileHandle = nullptr; // on windows, it is a a HANDLE, otherwise, it is a oslFileHandle #if defined(_WIN32) sal_uInt16 nLockCounter; #endif + OUString aFilename; bool bIsOpen; SvFileStream (const SvFileStream&) = delete; diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 8e145d20b964..c19d5b00b4b2 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -92,16 +92,6 @@ void unlockFile( SvFileStream const * pStream ) } -// StreamData ------------------------------------------------------------------ - -class StreamData -{ -public: - oslFileHandle rHandle; - - StreamData() : rHandle( nullptr ) { } -}; - static ErrCode GetSvError( int nErrno ) { static struct { int nErr; ErrCode sv; } const errArr[] = @@ -198,7 +188,6 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nOpenMode ) { bIsOpen = false; m_isWritable = false; - pInstanceData.reset(new StreamData); SetBufferSize( 1024 ); // convert URL to SystemPath, if necessary @@ -215,7 +204,6 @@ SvFileStream::SvFileStream() { bIsOpen = false; m_isWritable = false; - pInstanceData.reset(new StreamData); SetBufferSize( 1024 ); } @@ -231,7 +219,7 @@ std::size_t SvFileStream::GetData( void* pData, std::size_t nSize ) sal_uInt64 nRead = 0; if ( IsOpen() ) { - oslFileError rc = osl_readFile(pInstanceData->rHandle,pData,static_cast<sal_uInt64>(nSize),&nRead); + oslFileError rc = osl_readFile(mxFileHandle,pData,static_cast<sal_uInt64>(nSize),&nRead); if ( rc != osl_File_E_None ) { SetError( ::GetSvError( rc )); @@ -248,7 +236,7 @@ std::size_t SvFileStream::PutData( const void* pData, std::size_t nSize ) sal_uInt64 nWrite = 0; if ( IsOpen() ) { - oslFileError rc = osl_writeFile(pInstanceData->rHandle,pData,static_cast<sal_uInt64>(nSize),&nWrite); + oslFileError rc = osl_writeFile(mxFileHandle,pData,static_cast<sal_uInt64>(nSize),&nWrite); if ( rc != osl_File_E_None ) { SetError( ::GetSvError( rc ) ); @@ -269,9 +257,9 @@ sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) oslFileError rc; sal_uInt64 nNewPos; if ( nPos != STREAM_SEEK_TO_END ) - rc = osl_setFilePos( pInstanceData->rHandle, osl_Pos_Absolut, nPos ); + rc = osl_setFilePos( mxFileHandle, osl_Pos_Absolut, nPos ); else - rc = osl_setFilePos( pInstanceData->rHandle, osl_Pos_End, 0 ); + rc = osl_setFilePos( mxFileHandle, osl_Pos_End, 0 ); if ( rc != osl_File_E_None ) { @@ -280,7 +268,7 @@ sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) } if ( nPos != STREAM_SEEK_TO_END ) return nPos; - osl_getFilePos( pInstanceData->rHandle, &nNewPos ); + osl_getFilePos( mxFileHandle, &nNewPos ); return nNewPos; } SetError( SVSTREAM_GENERALERROR ); @@ -289,7 +277,7 @@ sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) void SvFileStream::FlushData() { - auto rc = osl_syncFile(pInstanceData->rHandle); + auto rc = osl_syncFile(mxFileHandle); if (rc != osl_File_E_None) SetError( ::GetSvError( rc )); } @@ -440,7 +428,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nOpenMode ) } if ( rc == osl_File_E_None ) { - pInstanceData->rHandle = nHandleTmp; + mxFileHandle = nHandleTmp; bIsOpen = true; if ( uFlags & osl_File_OpenFlag_Write ) m_isWritable = true; @@ -450,7 +438,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nOpenMode ) osl_closeFile( nHandleTmp ); bIsOpen = false; m_isWritable = false; - pInstanceData->rHandle = nullptr; + mxFileHandle = nullptr; } } else @@ -465,8 +453,8 @@ void SvFileStream::Close() { SAL_INFO("tools", "Closing " << aFilename); FlushBuffer(); - osl_closeFile( pInstanceData->rHandle ); - pInstanceData->rHandle = nullptr; + osl_closeFile( mxFileHandle ); + mxFileHandle = nullptr; } bIsOpen = false; @@ -485,7 +473,7 @@ void SvFileStream::SetSize (sal_uInt64 const nSize) { if (IsOpen()) { - oslFileError rc = osl_setFileSize( pInstanceData->rHandle, nSize ); + oslFileError rc = osl_setFileSize( mxFileHandle, nSize ); if (rc != osl_File_E_None ) { SetError ( ::GetSvError( rc )); diff --git a/tools/source/stream/strmwnt.cxx b/tools/source/stream/strmwnt.cxx index f88cbe307606..57f7c8b50c07 100644 --- a/tools/source/stream/strmwnt.cxx +++ b/tools/source/stream/strmwnt.cxx @@ -36,16 +36,6 @@ #include <osl/file.hxx> using namespace osl; -class StreamData -{ -public: - HANDLE hFile; - - StreamData() : hFile(nullptr) - { - } -}; - static ErrCode GetSvError( DWORD nWntError ) { static struct { DWORD wnt; ErrCode sv; } errArr[] = @@ -107,7 +97,6 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nMode ) bIsOpen = false; nLockCounter = 0; m_isWritable = false; - pInstanceData.reset( new StreamData ); SetBufferSize( 8192 ); // convert URL to SystemPath, if necessary @@ -123,7 +112,6 @@ SvFileStream::SvFileStream() bIsOpen = false; nLockCounter = 0; m_isWritable = false; - pInstanceData.reset( new StreamData ); SetBufferSize( 8192 ); } @@ -139,7 +127,7 @@ std::size_t SvFileStream::GetData( void* pData, std::size_t nSize ) DWORD nCount = 0; if( IsOpen() ) { - bool bResult = ReadFile(pInstanceData->hFile,pData,nSize,&nCount,nullptr); + bool bResult = ReadFile(mxFileHandle,pData,nSize,&nCount,nullptr); if( !bResult ) { std::size_t nTestError = GetLastError(); @@ -154,7 +142,7 @@ std::size_t SvFileStream::PutData( const void* pData, std::size_t nSize ) DWORD nCount = 0; if( IsOpen() ) { - if(!WriteFile(pInstanceData->hFile,pData,nSize,&nCount,nullptr)) + if(!WriteFile(mxFileHandle,pData,nSize,&nCount,nullptr)) SetError(::GetSvError( GetLastError() ) ); } return nCount; @@ -169,9 +157,9 @@ sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) { if( nPos != STREAM_SEEK_TO_END ) // 64-Bit files are not supported - nNewPos=SetFilePointer(pInstanceData->hFile,nPos,nullptr,FILE_BEGIN); + nNewPos=SetFilePointer(mxFileHandle,nPos,nullptr,FILE_BEGIN); else - nNewPos=SetFilePointer(pInstanceData->hFile,0L,nullptr,FILE_END); + nNewPos=SetFilePointer(mxFileHandle,0L,nullptr,FILE_END); if( nNewPos == 0xFFFFFFFF ) { @@ -188,7 +176,7 @@ void SvFileStream::FlushData() { if( IsOpen() ) { - if( !FlushFileBuffers(pInstanceData->hFile) ) + if( !FlushFileBuffers(mxFileHandle) ) SetError(::GetSvError(GetLastError())); } } @@ -200,7 +188,7 @@ bool SvFileStream::LockFile() { if( IsOpen() ) { - bRetVal = ::LockFile(pInstanceData->hFile,0L,0L,LONG_MAX,0L ); + bRetVal = ::LockFile(mxFileHandle,0L,0L,LONG_MAX,0L ); if( bRetVal ) { nLockCounter = 1; @@ -225,7 +213,7 @@ void SvFileStream::UnlockFile() { if( IsOpen() ) { - if( ::UnlockFile(pInstanceData->hFile,0L,0L,LONG_MAX,0L ) ) + if( ::UnlockFile(mxFileHandle,0L,0L,LONG_MAX,0L ) ) { nLockCounter = 0; } @@ -307,7 +295,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) if ( nMode & StreamMode::DELETE_ON_CLOSE ) nAttributes |= FILE_FLAG_DELETE_ON_CLOSE; - pInstanceData->hFile = CreateFileW( + mxFileHandle = CreateFileW( o3tl::toW(aFilename.getStr()), nAccessMode, nShareMode, @@ -317,7 +305,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) nullptr ); - if( pInstanceData->hFile!=INVALID_HANDLE_VALUE && ( + if( mxFileHandle!=INVALID_HANDLE_VALUE && ( // Did Create Always overwrite a file? GetLastError() == ERROR_ALREADY_EXISTS || // Did Create Always open a new file? @@ -329,7 +317,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) } // Otherwise, determine if we're allowed to read - if( (pInstanceData->hFile==INVALID_HANDLE_VALUE) && + if( (mxFileHandle==INVALID_HANDLE_VALUE) && (nAccessMode & GENERIC_WRITE)) { ErrCode nErr = ::GetSvError( GetLastError() ); @@ -341,7 +329,7 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) // if Openaction is CREATE_ALWAYS nOpenAction = OPEN_EXISTING; SetLastError( ERROR_SUCCESS ); - pInstanceData->hFile = CreateFileW( + mxFileHandle = CreateFileW( o3tl::toW(aFilename.getStr()), GENERIC_READ, nShareMode, @@ -380,7 +368,7 @@ void SvFileStream::Close() UnlockFile(); } FlushBuffer(); - CloseHandle( pInstanceData->hFile ); + CloseHandle( mxFileHandle ); } bIsOpen = false; nLockCounter= 0; @@ -401,7 +389,7 @@ void SvFileStream::SetSize(sal_uInt64 const nSize) if( IsOpen() ) { bool bError = false; - HANDLE hFile = pInstanceData->hFile; + HANDLE hFile = mxFileHandle; DWORD const nOld = SetFilePointer( hFile, 0L, nullptr, FILE_CURRENT ); if( nOld != 0xffffffff ) {