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 /ucb | |
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 'ucb')
-rw-r--r-- | ucb/source/ucp/cmis/std_inputstream.cxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/file/filstr.cxx | 3 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/NeonInputStream.cxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfInputStream.cxx | 2 |
4 files changed, 5 insertions, 4 deletions
diff --git a/ucb/source/ucp/cmis/std_inputstream.cxx b/ucb/source/ucp/cmis/std_inputstream.cxx index e6a1431f8f7b..2130c3406995 100644 --- a/ucb/source/ucp/cmis/std_inputstream.cxx +++ b/ucb/source/ucp/cmis/std_inputstream.cxx @@ -127,7 +127,7 @@ namespace cmis sal_Int32 SAL_CALL StdInputStream::available( ) { - return sal::static_int_cast< sal_Int32 >( m_nLength - getPosition() ); + return std::min<sal_Int64>( SAL_MAX_INT32, m_nLength - getPosition() ); } void SAL_CALL StdInputStream::closeInput( ) diff --git a/ucb/source/ucp/file/filstr.cxx b/ucb/source/ucp/file/filstr.cxx index 69fc4aa28283..2ef94c5e6529 100644 --- a/ucb/source/ucp/file/filstr.cxx +++ b/ucb/source/ucp/file/filstr.cxx @@ -170,7 +170,8 @@ XStream_impl::skipBytes( sal_Int32 nBytesToSkip ) sal_Int32 SAL_CALL XStream_impl::available() { - return 0; + sal_Int64 avail = getLength() - getPosition(); + return std::min<sal_Int64>(avail, SAL_MAX_INT32); } diff --git a/ucb/source/ucp/webdav-neon/NeonInputStream.cxx b/ucb/source/ucp/webdav-neon/NeonInputStream.cxx index 3e43456a1838..848dc2b81cf8 100644 --- a/ucb/source/ucp/webdav-neon/NeonInputStream.cxx +++ b/ucb/source/ucp/webdav-neon/NeonInputStream.cxx @@ -105,7 +105,7 @@ void SAL_CALL NeonInputStream::skipBytes( sal_Int32 nBytesToSkip ) // Returns the number of unread bytes currently remaining on the stream sal_Int32 SAL_CALL NeonInputStream::available( ) { - return sal::static_int_cast<sal_Int32>(mLen - mPos); + return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos); } void SAL_CALL NeonInputStream::closeInput() diff --git a/ucb/source/ucp/webdav/SerfInputStream.cxx b/ucb/source/ucp/webdav/SerfInputStream.cxx index f0f954d64855..498ed26e6c24 100644 --- a/ucb/source/ucp/webdav/SerfInputStream.cxx +++ b/ucb/source/ucp/webdav/SerfInputStream.cxx @@ -120,7 +120,7 @@ void SAL_CALL SerfInputStream::skipBytes( sal_Int32 nBytesToSkip ) sal_Int32 SAL_CALL SerfInputStream::available( ) { - return sal::static_int_cast<sal_Int32>(mLen - mPos); + return std::min<sal_Int64>(SAL_MAX_INT32, mLen - mPos); } |