Release 980712
[wine/multimedia.git] / multimedia / mmio.c
blob5d88542d23ff26e2912722efbb8caa0af22fa992
1 /*
2 * MMIO functions
4 * Copyright 1998 Andrew Taylor
6 * NOTES: I/O is still unbuffered; mmioSetBuffer must be implemented
7 * and mmio{Read,Write,Seek,others?} need buffer support.
8 * Buffering should almost give us memory files for free.
9 */
12 #include <stdlib.h>
13 #include <string.h>
14 #include <errno.h>
15 #include "windows.h"
16 #include "win.h"
17 #include "heap.h"
18 #include "user.h"
19 #include "file.h"
20 #include "mmsystem.h"
21 #include "debug.h"
22 #include "xmalloc.h"
24 /**************************************************************************
25 * mmioDosIOProc [internal]
27 static LRESULT mmioDosIOProc(LPMMIOINFO16 lpmmioinfo, UINT16 uMessage, LPARAM lParam1, LPARAM lParam2) {
28 TRACE(mmio, "(%p, %X, %ld, %ld);\n", lpmmioinfo, uMessage, lParam1, lParam2);
30 switch (uMessage) {
32 case MMIOM_OPEN: {
33 /* Parameters:
34 * lParam1 = szFileName parameter from mmioOpen
35 * lParam2 = unused
36 * Returns: zero on success, error code on error
37 * NOTE: lDiskOffset automatically set to zero
40 OFSTRUCT ofs;
41 LPSTR szFileName = (LPSTR) lParam1;
43 if (lpmmioinfo->dwFlags & MMIO_GETTEMP) {
44 FIXME(mmio, "MMIO_GETTEMP not implemented\n");
45 return MMIOERR_CANNOTOPEN;
48 /* if filename NULL, assume open file handle in adwInfo[0] */
49 if (!szFileName)
50 return 0;
52 lpmmioinfo->adwInfo[0] =
53 (DWORD) OpenFile32(szFileName, &ofs, lpmmioinfo->dwFlags);
54 if (lpmmioinfo->adwInfo[0] == -1)
55 return MMIOERR_CANNOTOPEN;
57 return 0;
60 case MMIOM_CLOSE: {
61 /* Parameters:
62 * lParam1 = wFlags parameter from mmioClose
63 * lParam2 = unused
64 * Returns: zero on success, error code on error
67 UINT16 uFlags = (UINT16) lParam1;
69 if (uFlags & MMIO_FHOPEN)
70 return 0;
72 _lclose32((HFILE32)lpmmioinfo->adwInfo[0]);
73 return 0;
77 case MMIOM_READ: {
78 /* Parameters:
79 * lParam1 = huge pointer to read buffer
80 * lParam2 = number of bytes to read
81 * Returns: number of bytes read, 0 for EOF, -1 for error (error code
82 * in wErrorRet)
83 * NOTE: lDiskOffset should be updated
86 HPSTR pch = (HPSTR) lParam1;
87 LONG cch = (LONG) lParam2;
88 LONG count;
90 count = _lread32((HFILE32)lpmmioinfo->adwInfo[0], pch, cch);
91 if (count != -1)
92 lpmmioinfo->lDiskOffset += count;
94 return count;
97 case MMIOM_WRITE:
98 case MMIOM_WRITEFLUSH: {
99 /* no internal buffering, so WRITEFLUSH handled same as WRITE */
101 /* Parameters:
102 * lParam1 = huge pointer to write buffer
103 * lParam2 = number of bytes to write
104 * Returns: number of bytes written, -1 for error (error code in
105 * wErrorRet)
106 * NOTE: lDiskOffset should be updated
109 HPSTR pch = (HPSTR) lParam1;
110 LONG cch = (LONG) lParam2;
111 LONG count;
113 count = _hwrite16((HFILE32)lpmmioinfo->adwInfo[0], pch, cch);
114 if (count != -1)
115 lpmmioinfo->lDiskOffset += count;
117 return count;
120 case MMIOM_SEEK: {
121 /* Parameters:
122 * lParam1 = new position
123 * lParam2 = from whence to seek (SEEK_SET, SEEK_CUR, SEEK_END)
124 * Returns: new file postion, -1 on error
125 * NOTE: lDiskOffset should be updated
128 LONG Offset = (LONG) lParam1;
129 LONG Whence = (LONG) lParam2;
130 LONG pos;
132 pos = _llseek32((HFILE32)lpmmioinfo->adwInfo[0], Offset, Whence);
133 if (pos != -1)
134 lpmmioinfo->lDiskOffset = pos;
136 return pos;
139 case MMIOM_RENAME: {
140 /* Parameters:
141 * lParam1 = old name
142 * lParam2 = new name
143 * Returns: zero on success, non-zero on failure
146 FIXME(mmio, "MMIOM_RENAME unimplemented\n");
147 return MMIOERR_FILENOTFOUND;
150 default:
151 FIXME(mmio, "unexpected message %u\n", uMessage);
152 return 0;
155 return 0;
158 /**************************************************************************
159 * mmioMemIOProc [internal]
161 static LRESULT mmioMemIOProc(LPMMIOINFO16 lpmmioinfo, UINT16 uMessage, LPARAM lParam1, LPARAM lParam2) {
162 FIXME(mmio,"(%p,0x%04x,0x%08lx,0x%08lx), stub!\n",lpmmioinfo,uMessage,lParam1,lParam2);
163 return 0;
166 /**************************************************************************
167 * mmioOpenW [WINMM.123]
169 HMMIO32 WINAPI mmioOpen32W(LPWSTR szFileName, MMIOINFO32 * lpmmioinfo,
170 DWORD dwOpenFlags)
172 LPSTR szFn = HEAP_strdupWtoA(GetProcessHeap(),0,szFileName);
173 HMMIO32 ret = mmioOpen16(szFn,(LPMMIOINFO16)lpmmioinfo,dwOpenFlags);
175 HeapFree(GetProcessHeap(),0,szFn);
176 return ret;
179 /**************************************************************************
180 * mmioOpenA [WINMM.122]
182 HMMIO32 WINAPI mmioOpen32A(LPSTR szFileName, MMIOINFO32 * lpmmioinfo,
183 DWORD dwOpenFlags)
185 return mmioOpen16(szFileName,(LPMMIOINFO16)lpmmioinfo,dwOpenFlags);
188 /**************************************************************************
189 * mmioOpen [MMSYSTEM.1210]
191 HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16 * lpmmioinfo,
192 DWORD dwOpenFlags)
194 LPMMIOINFO16 lpmminfo;
195 HMMIO16 hmmio;
196 UINT16 result;
198 TRACE(mmio, "('%s', %p, %08lX);\n", szFileName, lpmmioinfo, dwOpenFlags);
200 hmmio = GlobalAlloc16(GHND, sizeof(MMIOINFO16));
201 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
202 if (lpmminfo == NULL)
203 return 0;
204 memset(lpmminfo, 0, sizeof(MMIOINFO16));
206 /* assume DOS file if not otherwise specified */
207 if (!lpmmioinfo ||
208 (lpmmioinfo->fccIOProc == 0 && lpmmioinfo->pIOProc == NULL)) {
210 lpmminfo->fccIOProc = mmioFOURCC('D', 'O', 'S', ' ');
211 lpmminfo->pIOProc = (LPMMIOPROC16) mmioDosIOProc;
213 /* if just the four character code is present, look up IO proc */
214 else if (lpmmioinfo->pIOProc == NULL) {
216 lpmminfo->fccIOProc = lpmmioinfo->fccIOProc;
217 lpmminfo->pIOProc = mmioInstallIOProc16(lpmmioinfo->fccIOProc, NULL, MMIO_FINDPROC);
220 /* if IO proc specified, use it and specified four character code */
221 else {
223 lpmminfo->fccIOProc = lpmmioinfo->fccIOProc;
224 lpmminfo->pIOProc = lpmmioinfo->pIOProc;
227 if (dwOpenFlags & MMIO_ALLOCBUF) {
228 if ((result = mmioSetBuffer(hmmio, NULL, MMIO_DEFAULTBUFFER, 0))) {
229 if (lpmmioinfo)
230 lpmmioinfo->wErrorRet = result;
231 return 0;
235 lpmminfo->hmmio = hmmio;
237 /* call IO proc to actually open file */
238 result = (UINT16) mmioSendMessage(hmmio, MMIOM_OPEN, (LPARAM) szFileName, (LPARAM) 0);
240 GlobalUnlock16(hmmio);
242 if (result != 0) {
243 GlobalFree16(hmmio);
244 return 0;
247 return hmmio;
251 /**************************************************************************
252 * mmioClose [WINMM.114]
254 MMRESULT32 WINAPI mmioClose32(HMMIO32 hmmio, UINT32 uFlags)
256 LPMMIOINFO16 lpmminfo;
257 MMRESULT32 result;
259 TRACE(mmio, "(%04X, %04X);\n", hmmio, uFlags);
261 lpmminfo = (LPMMIOINFO16) GlobalLock16(hmmio);
262 if (lpmminfo == NULL)
263 return 0;
265 /* flush the file - if error reported, ignore */
266 if (mmioFlush32(hmmio, MMIO_EMPTYBUF) != 0)
267 lpmminfo->dwFlags &= ~MMIO_DIRTY;
269 result = mmioSendMessage(hmmio,MMIOM_CLOSE,(LPARAM)uFlags,(LPARAM)0);
271 mmioSetBuffer(hmmio, NULL, 0, 0);
273 GlobalUnlock16(hmmio);
274 GlobalFree16(hmmio);
276 return result;
280 /**************************************************************************
281 * mmioClose [MMSYSTEM.1211]
283 MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
285 return mmioClose32(hmmio,uFlags);
290 /**************************************************************************
291 * mmioRead [WINM.124]
293 LONG WINAPI mmioRead32(HMMIO32 hmmio, HPSTR pch, LONG cch)
295 LONG count;
296 LPMMIOINFO16 lpmminfo;
298 TRACE(mmio, "(%04X, %p, %ld);\n", hmmio, pch, cch);
300 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
301 if (lpmminfo == NULL)
302 return -1;
304 count = mmioSendMessage(hmmio, MMIOM_READ, (LPARAM) pch, (LPARAM) cch);
306 GlobalUnlock16(hmmio);
307 TRACE(mmio, "count=%ld\n", count);
308 return count;
311 /**************************************************************************
312 * mmioRead [MMSYSTEM.1212]
314 LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
316 return mmioRead32(hmmio,pch,cch);
319 /**************************************************************************
320 * mmioWrite [WINMM.133]
322 LONG WINAPI mmioWrite32(HMMIO32 hmmio, HPCSTR pch, LONG cch)
324 LONG count;
325 LPMMIOINFO16 lpmminfo;
327 TRACE(mmio, "(%04X, %p, %ld);\n", hmmio, pch, cch);
329 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
330 if (lpmminfo == NULL)
331 return -1;
333 count = mmioSendMessage(hmmio, MMIOM_WRITE, (LPARAM) pch, (LPARAM) cch);
335 GlobalUnlock16(hmmio);
336 TRACE(mmio, "count=%ld\n", count);
337 return count;
340 /**************************************************************************
341 * mmioWrite [MMSYSTEM.1213]
343 LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
345 return mmioWrite32(hmmio,pch,cch);
348 /**************************************************************************
349 * mmioSeek [MMSYSTEM.1214]
351 LONG WINAPI mmioSeek32(HMMIO32 hmmio, LONG lOffset, INT32 iOrigin)
353 int offset;
354 LPMMIOINFO16 lpmminfo;
356 TRACE(mmio, "(%04X, %08lX, %d);\n", hmmio, lOffset, iOrigin);
358 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
359 if (lpmminfo == NULL)
360 return 0;
362 offset = mmioSendMessage(hmmio, MMIOM_SEEK, (LPARAM) lOffset, (LPARAM) iOrigin);
364 GlobalUnlock16(hmmio);
365 return offset;
368 /**************************************************************************
369 * mmioSeek [MMSYSTEM.1214]
371 LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
373 return mmioSeek32(hmmio,lOffset,iOrigin);
376 /**************************************************************************
377 * mmioGetInfo [MMSYSTEM.1215]
379 UINT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16 * lpmmioinfo, UINT16 uFlags)
381 LPMMIOINFO16 lpmminfo;
382 TRACE(mmio, "mmioGetInfo\n");
383 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
384 if (lpmminfo == NULL) return 0;
385 memcpy(lpmmioinfo, lpmminfo, sizeof(MMIOINFO16));
386 GlobalUnlock16(hmmio);
387 return 0;
390 /**************************************************************************
391 * mmioGetInfo [WINMM.118]
393 UINT32 WINAPI mmioGetInfo32(HMMIO32 hmmio, MMIOINFO32*lpmmioinfo, UINT32 uFlags)
395 MMIOINFO16 mmioinfo;
396 LPMMIOINFO16 lpmminfo=&mmioinfo;
397 UINT16 ret;
399 TRACE(mmio, "(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
400 ret = mmioGetInfo16(hmmio,&mmioinfo,uFlags);
401 if (!ret)
402 return 0;
403 lpmmioinfo->dwFlags = lpmminfo->dwFlags;
404 lpmmioinfo->fccIOProc = lpmminfo->fccIOProc;
405 lpmmioinfo->pIOProc = (LPMMIOPROC32)lpmminfo->pIOProc;
406 lpmmioinfo->wErrorRet = lpmminfo->wErrorRet;
407 lpmmioinfo->htask = lpmminfo->htask;
408 lpmmioinfo->cchBuffer = lpmminfo->cchBuffer;
409 lpmmioinfo->pchBuffer = lpmminfo->pchBuffer;
410 lpmmioinfo->pchNext = lpmminfo->pchNext;
411 lpmmioinfo->pchEndRead = lpmminfo->pchEndRead;
412 lpmmioinfo->pchEndWrite = lpmminfo->pchEndWrite;
413 lpmmioinfo->lBufOffset = lpmminfo->lBufOffset;
414 lpmmioinfo->lDiskOffset = lpmminfo->lDiskOffset;
415 memcpy(lpmmioinfo->adwInfo,lpmminfo->adwInfo,sizeof(lpmminfo->adwInfo));
416 lpmmioinfo->dwReserved1 = lpmminfo->dwReserved1;
417 lpmmioinfo->dwReserved2 = lpmminfo->dwReserved2;
418 lpmmioinfo->hmmio = lpmminfo->hmmio;
419 return 0;
422 /**************************************************************************
423 * mmioSetInfo [MMSYSTEM.1216]
425 UINT16 WINAPI mmioSetInfo(HMMIO16 hmmio, const MMIOINFO16 * lpmmioinfo, UINT16 uFlags)
427 LPMMIOINFO16 lpmminfo;
428 TRACE(mmio, "mmioSetInfo\n");
429 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
430 if (lpmminfo == NULL) return 0;
431 GlobalUnlock16(hmmio);
432 return 0;
435 /**************************************************************************
436 * mmioSetBuffer [MMSYSTEM.1217]
438 UINT16 WINAPI mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer,
439 LONG cchBuffer, UINT16 uFlags)
441 FIXME(mmio, "(hmmio=%d, pchBuf=%p, cchBuf=%ld, uFlags=%#08x): stub\n",
442 hmmio, pchBuffer, cchBuffer, uFlags);
443 return (UINT16) 0;
444 /* stops Corel Draw 4 (16 bit) from working
445 return MMIOERR_OUTOFMEMORY;
449 /**************************************************************************
450 * mmioFlush [WINMM.117]
452 UINT32 WINAPI mmioFlush32(HMMIO32 hmmio, UINT32 uFlags)
454 LPMMIOINFO16 lpmminfo;
455 TRACE(mmio, "(%04X, %04X)\n", hmmio, uFlags);
456 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
457 if (lpmminfo == NULL) return 0;
458 GlobalUnlock16(hmmio);
459 return 0;
462 /**************************************************************************
463 * mmioFlush [MMSYSTEM.1218]
465 UINT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
467 return mmioFlush32(hmmio,uFlags);
470 /**************************************************************************
471 * mmioAdvance [MMSYSTEM.1219]
473 UINT32 WINAPI mmioAdvance32(HMMIO32 hmmio,MMIOINFO32*lpmmioinfo,UINT32 uFlags)
475 int count = 0;
476 LPMMIOINFO16 lpmminfo;
477 TRACE(mmio, "mmioAdvance\n");
478 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
479 if (lpmminfo == NULL) return 0;
480 if (uFlags == MMIO_READ)
481 count = _lread32(LOWORD(lpmminfo->adwInfo[0]),
482 lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer);
483 if (uFlags == MMIO_WRITE)
484 count = _lwrite32(LOWORD(lpmminfo->adwInfo[0]),
485 lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer);
486 lpmmioinfo->pchNext += count;
487 GlobalUnlock16(hmmio);
488 lpmminfo->lDiskOffset = _llseek32((HFILE32)lpmminfo->adwInfo[0], 0, SEEK_CUR);
489 return 0;
492 /**************************************************************************
493 * mmioAdvance [MMSYSTEM.1219]
495 UINT16 WINAPI mmioAdvance16(HMMIO16 hmmio,MMIOINFO16*lpmmioinfo,UINT16 uFlags)
497 int count = 0;
498 LPMMIOINFO16 lpmminfo;
499 TRACE(mmio, "mmioAdvance\n");
500 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
501 if (lpmminfo == NULL) return 0;
502 if (uFlags == MMIO_READ)
503 count = _lread32(LOWORD(lpmminfo->adwInfo[0]),
504 lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer);
505 if (uFlags == MMIO_WRITE)
506 count = _lwrite32(LOWORD(lpmminfo->adwInfo[0]),
507 lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer);
508 lpmmioinfo->pchNext += count;
509 GlobalUnlock16(hmmio);
510 lpmminfo->lDiskOffset = _llseek32((HFILE32)lpmminfo->adwInfo[0], 0, SEEK_CUR);
511 return 0;
514 /**************************************************************************
515 * mmioStringToFOURCCA [WINMM.131]
517 FOURCC WINAPI mmioStringToFOURCC32A(LPCSTR sz, UINT32 uFlags)
519 return mmioStringToFOURCC16(sz,uFlags);
522 /**************************************************************************
523 * mmioStringToFOURCCW [WINMM.132]
525 FOURCC WINAPI mmioStringToFOURCC32W(LPCWSTR sz, UINT32 uFlags)
527 LPSTR szA = HEAP_strdupWtoA(GetProcessHeap(),0,sz);
528 FOURCC ret = mmioStringToFOURCC32A(szA,uFlags);
530 HeapFree(GetProcessHeap(),0,szA);
531 return ret;
534 /**************************************************************************
535 * mmioStringToFOURCC [MMSYSTEM.1220]
537 FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
539 return mmioFOURCC(sz[0],sz[1],sz[2],sz[3]);
542 /**************************************************************************
543 * mmioInstallIOProc16 [MMSYSTEM.1221]
545 LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc,
546 LPMMIOPROC16 pIOProc, DWORD dwFlags)
548 TRACE(mmio, "(%ld, %p, %08lX)\n",
549 fccIOProc, pIOProc, dwFlags);
551 if (dwFlags & MMIO_GLOBALPROC) {
552 FIXME(mmio, " global procedures not implemented\n");
555 /* just handle the known procedures for now */
556 switch(dwFlags & (MMIO_INSTALLPROC|MMIO_REMOVEPROC|MMIO_FINDPROC)) {
557 case MMIO_INSTALLPROC:
558 return NULL;
559 case MMIO_REMOVEPROC:
560 return NULL;
561 case MMIO_FINDPROC:
562 if (fccIOProc == FOURCC_DOS)
563 return (LPMMIOPROC16) mmioDosIOProc;
564 else if (fccIOProc == FOURCC_MEM)
565 return (LPMMIOPROC16) mmioMemIOProc;
566 else
567 return NULL;
568 default:
569 return NULL;
573 /**************************************************************************
574 * mmioInstallIOProc32A [WINMM.120]
576 LPMMIOPROC32 WINAPI mmioInstallIOProc32A(FOURCC fccIOProc,
577 LPMMIOPROC32 pIOProc, DWORD dwFlags)
579 FIXME(mmio, "(%c%c%c%c,%p,0x%08lx) -- empty stub \n",
580 (char)((fccIOProc&0xff000000)>>24),
581 (char)((fccIOProc&0x00ff0000)>>16),
582 (char)((fccIOProc&0x0000ff00)>> 8),
583 (char)(fccIOProc&0x000000ff),
584 pIOProc, dwFlags );
585 return 0;
588 /**************************************************************************
589 * mmioSendMessage [MMSYSTEM.1222]
591 LRESULT WINAPI mmioSendMessage(HMMIO16 hmmio, UINT16 uMessage,
592 LPARAM lParam1, LPARAM lParam2)
594 LPMMIOINFO16 lpmminfo;
595 LRESULT result;
596 const char *msg = NULL;
598 #ifdef DEBUG_RUNTIME
599 switch (uMessage) {
600 #define msgname(x) case x: msg = #x; break;
601 msgname(MMIOM_OPEN);
602 msgname(MMIOM_CLOSE);
603 msgname(MMIOM_READ);
604 msgname(MMIOM_WRITE);
605 msgname(MMIOM_WRITEFLUSH);
606 msgname(MMIOM_SEEK);
607 msgname(MMIOM_RENAME);
608 #undef msgname
610 #endif
612 if (msg)
613 TRACE(mmio, "(%04X, %s, %ld, %ld)\n",
614 hmmio, msg, lParam1, lParam2);
615 else
616 TRACE(mmio, "(%04X, %u, %ld, %ld)\n",
617 hmmio, uMessage, lParam1, lParam2);
619 lpmminfo = (LPMMIOINFO16)GlobalLock16(hmmio);
621 if (lpmminfo && lpmminfo->pIOProc)
622 result = (*lpmminfo->pIOProc)((LPSTR)lpmminfo, uMessage, lParam1, lParam2);
623 else
624 result = MMSYSERR_INVALPARAM;
626 GlobalUnlock16(hmmio);
628 return result;
631 /**************************************************************************
632 * mmioDescend [MMSYSTEM.1223]
634 UINT16 WINAPI mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
635 const MMCKINFO * lpckParent, UINT16 uFlags)
637 DWORD dwfcc, dwOldPos;
639 TRACE(mmio, "(%04X, %p, %p, %04X);\n",
640 hmmio, lpck, lpckParent, uFlags);
642 if (lpck == NULL)
643 return 0;
645 dwfcc = lpck->ckid;
646 TRACE(mmio, "dwfcc=%08lX\n", dwfcc);
648 dwOldPos = mmioSeek32(hmmio, 0, SEEK_CUR);
649 TRACE(mmio, "dwOldPos=%ld\n", dwOldPos);
651 if (lpckParent != NULL) {
652 TRACE(mmio, "seek inside parent at %ld !\n", lpckParent->dwDataOffset);
653 dwOldPos = mmioSeek32(hmmio,lpckParent->dwDataOffset,SEEK_SET);
657 It seems to be that FINDRIFF should not be treated the same as the
658 other FINDxxx so I treat it as a MMIO_FINDxxx
660 if ((uFlags & MMIO_FINDCHUNK) || (uFlags & MMIO_FINDRIFF) ||
661 (uFlags & MMIO_FINDLIST)) {
663 if ((uFlags & MMIO_FINDCHUNK) || (uFlags & MMIO_FINDLIST)) {
664 TRACE(mmio, "MMIO_FINDxxxx dwfcc=%08lX !\n", dwfcc);
665 while (TRUE) {
666 LONG ix;
668 ix = mmioRead32(hmmio, (LPSTR)lpck, sizeof(MMCKINFO));
669 TRACE(mmio, "after _lread32 ix = %ld req = %d, errno = %d\n",ix,sizeof(MMCKINFO),errno);
670 if (ix < sizeof(MMCKINFO)) {
672 mmioSeek32(hmmio, dwOldPos, SEEK_SET);
673 WARN(mmio, "return ChunkNotFound\n");
674 return MMIOERR_CHUNKNOTFOUND;
676 TRACE(mmio, "dwfcc=%08lX ckid=%08lX cksize=%08lX !\n",
677 dwfcc, lpck->ckid, lpck->cksize);
678 if (dwfcc == lpck->ckid)
679 break;
681 dwOldPos += lpck->cksize + 2 * sizeof(DWORD);
682 if (lpck->ckid == FOURCC_RIFF || lpck->ckid == FOURCC_LIST)
683 dwOldPos += sizeof(DWORD);
684 mmioSeek32(hmmio, dwOldPos, SEEK_SET);
687 else {
688 if (mmioRead32(hmmio, (LPSTR)lpck, sizeof(MMCKINFO)) < sizeof(MMCKINFO)) {
689 mmioSeek32(hmmio, dwOldPos, SEEK_SET);
690 WARN(mmio, "return ChunkNotFound 2nd\n");
691 return MMIOERR_CHUNKNOTFOUND;
694 lpck->dwDataOffset = dwOldPos + 2 * sizeof(DWORD);
695 if (lpck->ckid == FOURCC_RIFF || lpck->ckid == FOURCC_LIST)
696 lpck->dwDataOffset += sizeof(DWORD);
697 mmioSeek32(hmmio, lpck->dwDataOffset, SEEK_SET);
699 TRACE(mmio, "lpck->ckid=%08lX lpck->cksize=%ld !\n",
700 lpck->ckid, lpck->cksize);
701 TRACE(mmio, "lpck->fccType=%08lX !\n", lpck->fccType);
703 return 0;
706 /**************************************************************************
707 * mmioAscend [WINMM.113]
709 UINT32 WINAPI mmioAscend32(HMMIO32 hmmio, MMCKINFO * lpck, UINT32 uFlags)
711 FIXME(mmio, "empty stub !\n");
712 return 0;
715 /**************************************************************************
716 * mmioAscend [MMSYSTEM.1224]
718 UINT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
720 return mmioAscend32(hmmio,lpck,uFlags);
723 /**************************************************************************
724 * mmioCreateChunk [MMSYSTEM.1225]
726 UINT16 WINAPI mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
728 FIXME(mmio, "empty stub \n");
729 return 0;
733 /**************************************************************************
734 * mmioRename [MMSYSTEM.1226]
736 UINT16 WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
737 MMIOINFO16 * lpmmioinfo, DWORD dwRenameFlags)
739 UINT16 result;
740 LPMMIOINFO16 lpmminfo;
741 HMMIO16 hmmio;
743 TRACE(mmio, "('%s', '%s', %p, %08lX);\n",
744 szFileName, szNewFileName, lpmmioinfo, dwRenameFlags);
746 hmmio = GlobalAlloc16(GHND, sizeof(MMIOINFO16));
747 lpmminfo = (LPMMIOINFO16) GlobalLock16(hmmio);
749 if (lpmmioinfo)
750 memcpy(lpmminfo, lpmmioinfo, sizeof(MMIOINFO16));
752 /* assume DOS file if not otherwise specified */
753 if (lpmminfo->fccIOProc == 0 && lpmminfo->pIOProc == NULL) {
755 lpmminfo->fccIOProc = mmioFOURCC('D', 'O', 'S', ' ');
756 lpmminfo->pIOProc = (LPMMIOPROC16) mmioDosIOProc;
759 /* if just the four character code is present, look up IO proc */
760 else if (lpmminfo->pIOProc == NULL) {
762 lpmminfo->pIOProc = mmioInstallIOProc16(lpmminfo->fccIOProc, NULL, MMIO_FINDPROC);
765 /* (if IO proc specified, use it and specified four character code) */
767 result = (UINT16) mmioSendMessage(hmmio, MMIOM_RENAME, (LPARAM) szFileName, (LPARAM) szNewFileName);
769 GlobalUnlock16(hmmio);
770 GlobalFree16(hmmio);
772 return result;