diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-11 09:57:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-11 12:55:47 +0200 |
commit | 00850e3fa71cc9ebeacad65f54a98b9a79a8b183 (patch) | |
tree | 69fef16ff20bb6e8b74d093bb3a31201bb72ceb8 /unotools | |
parent | ce795510d3de7beb6bcd39954280bc3b5778ec6e (diff) |
clean up UNO available() implementations
There seems to be some confusion here. available() is actually the
number of bytes that can be read without blocking, but most
implementations seems to be just returning the number of bytes remaining
in the stream. Since we're doing that, let's do it properly.
(*) some of them were just casting, instead of clamping, which will
return wrong values sometimes.
(*) FileStreamWrapper_Impl/OInputStreamWrapper/OTempFileService were
doing unnecessary work, instead of just asking the underlying SvStream
for it's remaining size
Change-Id: I3ef26e0363e989ed3e00be0fdb993e1cdeb7819f
Reviewed-on: https://gerrit.libreoffice.org/57264
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/streaming/streamwrap.cxx | 11 | ||||
-rw-r--r-- | unotools/source/ucbhelper/xtempfile.cxx | 5 |
2 files changed, 4 insertions, 12 deletions
diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx index fc68b8df300d..bcc365d961b1 100644 --- a/unotools/source/streaming/streamwrap.cxx +++ b/unotools/source/streaming/streamwrap.cxx @@ -107,17 +107,10 @@ sal_Int32 SAL_CALL OInputStreamWrapper::available() ::osl::MutexGuard aGuard( m_aMutex ); checkConnected(); - sal_uInt32 nPos = m_pSvStream->Tell(); - checkError(); - - m_pSvStream->Seek(STREAM_SEEK_TO_END); - checkError(); - - sal_Int32 nAvailable = static_cast<sal_Int32>(m_pSvStream->Tell()) - nPos; - m_pSvStream->Seek(nPos); + sal_Int64 nAvailable = m_pSvStream->remainingSize(); checkError(); - return nAvailable; + return std::min<sal_Int64>(SAL_MAX_INT32, nAvailable); } void SAL_CALL OInputStreamWrapper::closeInput() diff --git a/unotools/source/ucbhelper/xtempfile.cxx b/unotools/source/ucbhelper/xtempfile.cxx index a9c955caf5c3..5437044b8586 100644 --- a/unotools/source/ucbhelper/xtempfile.cxx +++ b/unotools/source/ucbhelper/xtempfile.cxx @@ -206,11 +206,10 @@ sal_Int32 SAL_CALL OTempFileService::available( ) checkConnected(); - sal_uInt32 const nAvailable = - static_cast<sal_uInt32>(mpStream->remainingSize()); + sal_Int64 nAvailable = mpStream->remainingSize(); checkError(); - return nAvailable; + return std::min<sal_Int64>(SAL_MAX_INT32, nAvailable); } void SAL_CALL OTempFileService::closeInput( ) { |