Peter Oberndorfer : shlwapi: Implement IStream::Write, Seek and SetSize.
Alexandre Julliard
julliard at winehq.org
Tue Sep 29 11:09:05 CDT 2009
Module: wine
Branch: master
Commit: 58669ece91161803f68ded7cb881a4b2511e45b8
URL: http://source.winehq.org/git/wine.git/?a=commit;h=58669ece91161803f68ded7cb881a4b2511e45b8
Author: Peter Oberndorfer <kumbayo84 at arcor.de>
Date: Mon Sep 28 22:24:08 2009 +0200
shlwapi: Implement IStream::Write, Seek and SetSize.
On Write holes between file size and cursor are filled with 0 bytes.
On SetSize holes caused by increasing file size are filled with 0 bytes.
---
dlls/shlwapi/regstream.c | 60 +++++++++++++++++++++++++++++++++++++++------
1 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/dlls/shlwapi/regstream.c b/dlls/shlwapi/regstream.c
index caee2e8..cd48d93 100644
--- a/dlls/shlwapi/regstream.c
+++ b/dlls/shlwapi/regstream.c
@@ -144,13 +144,29 @@ static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG
static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
{
ISHRegStream *This = (ISHRegStream *)iface;
+ DWORD newLen = This->dwPos + cb;
- TRACE("(%p)\n",This);
+ TRACE("(%p, %p, %d, %p)\n",This, pv, cb, pcbWritten);
+
+ if (newLen < This->dwPos) /* overflow */
+ return STG_E_INSUFFICIENTMEMORY;
+
+ if (newLen > This->dwLength)
+ {
+ LPBYTE newBuf = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pbBuffer, newLen);
+ if (!newBuf)
+ return STG_E_INSUFFICIENTMEMORY;
+
+ This->dwLength = newLen;
+ This->pbBuffer = newBuf;
+ }
+ memmove(This->pbBuffer + This->dwPos, pv, cb);
+ This->dwPos += cb; /* adjust pointer */
if (pcbWritten)
- *pcbWritten = 0;
+ *pcbWritten = cb;
- return E_NOTIMPL;
+ return S_OK;
}
/**************************************************************************
@@ -159,12 +175,28 @@ static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb
static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
{
ISHRegStream *This = (ISHRegStream *)iface;
+ LARGE_INTEGER tmp;
+ TRACE("(%p, %s, %d %p)\n", This,
+ wine_dbgstr_longlong(dlibMove.QuadPart), dwOrigin, plibNewPosition);
+
+ if (dwOrigin == STREAM_SEEK_SET)
+ tmp = dlibMove;
+ else if (dwOrigin == STREAM_SEEK_CUR)
+ tmp.QuadPart = This->dwPos + dlibMove.QuadPart;
+ else if (dwOrigin == STREAM_SEEK_END)
+ tmp.QuadPart = This->dwLength + dlibMove.QuadPart;
+ else
+ return STG_E_INVALIDPARAMETER;
- TRACE("(%p)\n",This);
+ if (tmp.QuadPart < 0)
+ return STG_E_INVALIDFUNCTION;
+
+ /* we cut off the high part here */
+ This->dwPos = tmp.LowPart;
if (plibNewPosition)
- plibNewPosition->QuadPart = 0;
- return E_NOTIMPL;
+ plibNewPosition->QuadPart = This->dwPos;
+ return S_OK;
}
/**************************************************************************
@@ -173,9 +205,21 @@ static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, D
static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
{
ISHRegStream *This = (ISHRegStream *)iface;
+ DWORD newLen;
+ LPBYTE newBuf;
- TRACE("(%p)\n",This);
- return E_NOTIMPL;
+ TRACE("(%p, %s)\n", This, wine_dbgstr_longlong(libNewSize.QuadPart));
+
+ /* we cut off the high part here */
+ newLen = libNewSize.LowPart;
+ newBuf = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pbBuffer, newLen);
+ if (!newBuf)
+ return STG_E_INSUFFICIENTMEMORY;
+
+ This->pbBuffer = newBuf;
+ This->dwLength = newLen;
+
+ return S_OK;
}
/**************************************************************************
More information about the wine-cvs
mailing list