Fixed another bunch of bugs (mainly linked to operations where file

pointer was past the end of file).
This commit is contained in:
Eric Pouech 2001-12-21 20:28:09 +00:00 committed by Alexandre Julliard
parent 4f07f05716
commit 090629242b
2 changed files with 29 additions and 23 deletions

View File

@ -43,7 +43,7 @@ static LRESULT CALLBACK mmioDosIOProc(LPMMIOINFO lpmmioinfo, UINT uMessage,
{ {
LRESULT ret = MMSYSERR_NOERROR; LRESULT ret = MMSYSERR_NOERROR;
TRACE("(%p, %X, %ld, %ld);\n", lpmmioinfo, uMessage, lParam1, lParam2); TRACE("(%p, %X, 0x%lx, 0x%lx);\n", lpmmioinfo, uMessage, lParam1, lParam2);
switch (uMessage) { switch (uMessage) {
case MMIOM_OPEN: case MMIOM_OPEN:
@ -68,9 +68,7 @@ static LRESULT CALLBACK mmioDosIOProc(LPMMIOINFO lpmmioinfo, UINT uMessage,
lpmmioinfo->adwInfo[0] = DosFileHandleToWin32Handle(lpmmioinfo->adwInfo[0]); lpmmioinfo->adwInfo[0] = DosFileHandleToWin32Handle(lpmmioinfo->adwInfo[0]);
break; break;
} }
lpmmioinfo->adwInfo[0] = (DWORD)OpenFile(szFileName, &ofs, lpmmioinfo->dwFlags & 0xFFFF);
lpmmioinfo->adwInfo[0] = (DWORD)OpenFile(szFileName, &ofs,
lpmmioinfo->dwFlags);
if (lpmmioinfo->adwInfo[0] == (DWORD)HFILE_ERROR) if (lpmmioinfo->adwInfo[0] == (DWORD)HFILE_ERROR)
ret = MMIOERR_CANNOTOPEN; ret = MMIOERR_CANNOTOPEN;
} }
@ -163,6 +161,7 @@ static LRESULT CALLBACK mmioMemIOProc(LPMMIOINFO lpmmioinfo, UINT uMessage,
/* FIXME: io proc shouldn't change it */ /* FIXME: io proc shouldn't change it */
if (!(lpmmioinfo->dwFlags & MMIO_CREATE)) if (!(lpmmioinfo->dwFlags & MMIO_CREATE))
lpmmioinfo->pchEndRead = lpmmioinfo->pchEndWrite; lpmmioinfo->pchEndRead = lpmmioinfo->pchEndWrite;
lpmmioinfo->adwInfo[0] = HFILE_ERROR;
return 0; return 0;
case MMIOM_CLOSE: case MMIOM_CLOSE:
@ -769,8 +768,8 @@ static HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
wm->ioProc->count++; wm->ioProc->count++;
if (dwOpenFlags & MMIO_ALLOCBUF) { if (dwOpenFlags & MMIO_ALLOCBUF) {
if ((refmminfo->wErrorRet = mmioSetBuffer(wm->info.hmmio, NULL, if ((refmminfo->wErrorRet = MMIO_SetBuffer(wm, NULL, MMIO_DEFAULTBUFFER, 0,
MMIO_DEFAULTBUFFER, 0))) type != MMIO_PROC_16)))
goto error1; goto error1;
} else if (wm->info.fccIOProc == FOURCC_MEM) { } else if (wm->info.fccIOProc == FOURCC_MEM) {
refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer, refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer,
@ -789,6 +788,9 @@ static HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
refmminfo->wErrorRet = MMIO_SendMessage(wm, MMIOM_OPEN, (LPARAM)szFileName, refmminfo->wErrorRet = MMIO_SendMessage(wm, MMIOM_OPEN, (LPARAM)szFileName,
type == MMIO_PROC_16, MMIO_PROC_32A); type == MMIO_PROC_16, MMIO_PROC_32A);
/* grab file size, when possible */
wm->dwFileSize = GetFileSize(wm->info.adwInfo[0], NULL);
if (refmminfo->wErrorRet == 0) if (refmminfo->wErrorRet == 0)
return wm->info.hmmio; return wm->info.hmmio;
error1: error1:
@ -904,7 +906,7 @@ MMRESULT WINAPI mmioClose(HMMIO hmmio, UINT uFlags)
result = MMIO_SendMessage(wm, MMIOM_CLOSE, uFlags, 0, MMIO_PROC_32A); result = MMIO_SendMessage(wm, MMIOM_CLOSE, uFlags, 0, MMIO_PROC_32A);
mmioSetBuffer(hmmio, NULL, 0, 0); MMIO_SetBuffer(wm, NULL, 0, 0, TRUE);
wm->ioProc->count--; wm->ioProc->count--;
@ -1069,25 +1071,28 @@ LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
offset = wm->info.lBufOffset + (wm->info.pchNext - wm->info.pchBuffer) + lOffset; offset = wm->info.lBufOffset + (wm->info.pchNext - wm->info.pchBuffer) + lOffset;
break; break;
case SEEK_END: case SEEK_END:
if (wm->info.fccIOProc == FOURCC_MEM) { offset = ((wm->info.fccIOProc == FOURCC_MEM)? wm->info.cchBuffer : wm->dwFileSize) - lOffset;
offset = wm->info.cchBuffer;
} else {
assert(MMIO_SendMessage(wm, MMIOM_SEEK, 0, SEEK_CUR, MMIO_PROC_32A) == wm->info.lDiskOffset);
offset = MMIO_SendMessage(wm, MMIOM_SEEK, 0, SEEK_END, MMIO_PROC_32A);
MMIO_SendMessage(wm, MMIOM_SEEK, wm->info.lDiskOffset, SEEK_SET, MMIO_PROC_32A);
}
offset -= lOffset;
break; break;
default: default:
return -1; return -1;
} }
/* stay in same buffer ? */ if (offset && offset >= wm->dwFileSize && wm->info.fccIOProc != FOURCC_MEM) {
/* some memory mapped buffers are defined with -1 as a size */ /* should check that write mode exists */
if ((wm->info.cchBuffer > 0) && if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR)
return -1;
wm->info.lBufOffset = offset;
wm->info.pchEndRead = wm->info.pchBuffer;
wm->info.pchEndWrite = wm->info.pchBuffer + wm->info.cchBuffer;
if ((wm->info.dwFlags & MMIO_RWMODE) == MMIO_READ) {
wm->info.lDiskOffset = wm->dwFileSize;
}
} else if ((wm->info.cchBuffer > 0) &&
((offset < wm->info.lBufOffset) || ((offset < wm->info.lBufOffset) ||
(offset >= wm->info.lBufOffset + wm->info.cchBuffer) || (offset >= wm->info.lBufOffset + wm->info.cchBuffer) ||
!wm->bBufferLoaded)) { !wm->bBufferLoaded)) {
/* stay in same buffer ? */
/* some memory mapped buffers are defined with -1 as a size */
/* condition to change buffer */ /* condition to change buffer */
if ((wm->info.fccIOProc == FOURCC_MEM) || if ((wm->info.fccIOProc == FOURCC_MEM) ||
@ -1305,7 +1310,6 @@ MMRESULT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
if (uFlags == MMIO_WRITE && (lpmmioinfo->dwFlags & MMIO_DIRTY)) if (uFlags == MMIO_WRITE && (lpmmioinfo->dwFlags & MMIO_DIRTY))
{ {
FIXME("writing data to disk\n");
MMIO_SendMessage(wm, MMIOM_SEEK, lpmmioinfo->lBufOffset, SEEK_SET, MMIO_PROC_32A); MMIO_SendMessage(wm, MMIOM_SEEK, lpmmioinfo->lBufOffset, SEEK_SET, MMIO_PROC_32A);
MMIO_SendMessage(wm, MMIOM_WRITE, (LPARAM)lpmmioinfo->pchBuffer, MMIO_SendMessage(wm, MMIOM_WRITE, (LPARAM)lpmmioinfo->pchBuffer,
lpmmioinfo->pchNext - lpmmioinfo->pchBuffer, MMIO_PROC_32A); lpmmioinfo->pchNext - lpmmioinfo->pchBuffer, MMIO_PROC_32A);
@ -1313,6 +1317,7 @@ MMRESULT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
} }
if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR) if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR)
return MMIOERR_CANNOTWRITE; return MMIOERR_CANNOTWRITE;
wm->dwFileSize = max(wm->dwFileSize, lpmmioinfo->lBufOffset + (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer));
MMIO_GrabNextBuffer(wm, uFlags == MMIO_READ); MMIO_GrabNextBuffer(wm, uFlags == MMIO_READ);

View File

@ -140,6 +140,7 @@ typedef struct tagWINE_MMIO {
SEGPTR buffer16; SEGPTR buffer16;
struct tagWINE_MMIO* lpNext; struct tagWINE_MMIO* lpNext;
BOOL bBufferLoaded; BOOL bBufferLoaded;
DWORD dwFileSize;
} WINE_MMIO, *LPWINE_MMIO; } WINE_MMIO, *LPWINE_MMIO;
typedef struct tagWINE_MM_IDATA { typedef struct tagWINE_MM_IDATA {