storage.dll16: Simplify operations in IStream16::Seek.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2017-02-14 09:41:53 -06:00 committed by Alexandre Julliard
parent 163ebdfa96
commit 3085e73392
1 changed files with 24 additions and 35 deletions

View File

@ -1179,44 +1179,33 @@ ULONG CDECL IStream16_fnRelease(IStream16 *iface)
* Does not handle 64 bits
*/
HRESULT CDECL IStream16_fnSeek(IStream16 *iface, LARGE_INTEGER offset, DWORD whence,
ULARGE_INTEGER *newpos)
ULARGE_INTEGER *newpos)
{
IStream16Impl *This = impl_from_IStream16(iface);
TRACE_(relay)("(%p)->([%d.%d],%d,%p)\n",This,offset.u.HighPart,offset.u.LowPart,whence,newpos);
IStream16Impl *This = impl_from_IStream16(iface);
TRACE_(relay)("(%p)->([%d.%d],%d,%p)\n",This,offset.u.HighPart,offset.u.LowPart,whence,newpos);
switch (whence) {
/* unix SEEK_xx should be the same as win95 ones */
case SEEK_SET:
/* offset must be ==0 (<0 is invalid, and >0 cannot be handled
* right now.
*/
assert(offset.u.HighPart==0);
This->offset.u.HighPart = offset.u.HighPart;
This->offset.u.LowPart = offset.u.LowPart;
break;
case SEEK_CUR:
if (offset.u.HighPart < 0) {
/* FIXME: is this negation correct ? */
offset.u.HighPart = -offset.u.HighPart;
offset.u.LowPart = (0xffffffff ^ offset.u.LowPart)+1;
switch (whence) {
case STREAM_SEEK_SET:
This->offset.QuadPart = offset.QuadPart;
break;
case STREAM_SEEK_CUR:
if ((offset.QuadPart < 0 && -offset.QuadPart > This->offset.QuadPart) ||
(offset.QuadPart > 0 && -offset.QuadPart <= This->offset.QuadPart))
return STG_E_INVALIDFUNCTION;
This->offset.QuadPart += offset.QuadPart;
break;
case STREAM_SEEK_END:
if (-offset.QuadPart > This->stde.pps_size)
return STG_E_INVALIDFUNCTION;
assert(offset.u.HighPart==0);
assert(This->offset.u.LowPart >= offset.u.LowPart);
This->offset.u.LowPart -= offset.u.LowPart;
} else {
assert(offset.u.HighPart==0);
This->offset.u.LowPart+= offset.u.LowPart;
}
break;
case SEEK_END:
assert(offset.u.HighPart==0);
This->offset.u.LowPart = This->stde.pps_size-offset.u.LowPart;
break;
}
if (This->offset.u.LowPart>This->stde.pps_size)
This->offset.u.LowPart=This->stde.pps_size;
if (newpos) *newpos = This->offset;
return S_OK;
This->offset.QuadPart = This->stde.pps_size + offset.QuadPart;
break;
}
if (This->offset.QuadPart>This->stde.pps_size)
This->offset.QuadPart=This->stde.pps_size;
if (newpos) *newpos = This->offset;
return S_OK;
}
/******************************************************************************