[PATCH v2] winmm: Pass a fullpath to CreateFileA
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair(a)hotmail.com> --- dlls/winmm/mmio.c | 18 +++++++++++++++++- dlls/winmm/tests/mmio.c | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index 48bbd3ed48..a3e2650f50 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -52,6 +52,9 @@ static WINE_MMIO *MMIOList; static HANDLE create_file_OF( LPCSTR path, INT mode ) { DWORD access, sharing, creation; + HANDLE ret; + char *fullpath = NULL; + DWORD len; if (mode & OF_CREATE) { @@ -79,7 +82,20 @@ static HANDLE create_file_OF( LPCSTR path, INT mode ) case OF_SHARE_COMPAT: default: sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; } - return CreateFileA( path, access, sharing, NULL, creation, FILE_ATTRIBUTE_NORMAL, 0 ); + + len = SearchPathA( NULL, path, NULL, 0, fullpath, NULL ); + if (!len) + return CreateFileA( path, access, sharing, NULL, creation, FILE_ATTRIBUTE_NORMAL, 0 ); + + fullpath = HeapAlloc(GetProcessHeap(), 0, len); + if (!fullpath) + return INVALID_HANDLE_VALUE; + + SearchPathA( NULL, path, NULL, len, fullpath, NULL ); + ret = CreateFileA( fullpath, access, sharing, NULL, creation, FILE_ATTRIBUTE_NORMAL, 0 ); + + HeapFree(GetProcessHeap(), 0, fullpath); + return ret; } /************************************************************************** diff --git a/dlls/winmm/tests/mmio.c b/dlls/winmm/tests/mmio.c index e3984fbaf3..0de51a2562 100644 --- a/dlls/winmm/tests/mmio.c +++ b/dlls/winmm/tests/mmio.c @@ -478,6 +478,7 @@ static void test_mmioOpen_create(void) WCHAR cwd[MAX_PATH], temp_dir[MAX_PATH]; /* According to docs, filename must be no more than 128 bytes, but it will * actually allow longer than that. */ + WCHAR relpath[] = L"local\\examplefile"; WCHAR filename[] = L"very_long_filename_" L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -520,6 +521,14 @@ static void test_mmioOpen_create(void) DeleteFileW(filename); + CreateDirectoryA("local", NULL); + hmmio = mmioOpenW(relpath, NULL, MMIO_CREATE | MMIO_WRITE | MMIO_EXCLUSIVE); + ok(hmmio != NULL, "mmioOpen failed\n"); + mmioClose(hmmio, 0); + + DeleteFileW(relpath); + RemoveDirectoryA("local"); + SetCurrentDirectoryW(cwd); } -- 2.28.0
Alistair Leslie-Hughes <leslie_alistair(a)hotmail.com> wrote:
static HANDLE create_file_OF( LPCSTR path, INT mode ) { DWORD access, sharing, creation; + HANDLE ret; + char *fullpath = NULL;
Initialization to NULL is redundant, you could pass NULL directly to SearchPath(). -- Dmitry.
On Mon, Aug 31, 2020 at 05:33:58PM +1000, Alistair Leslie-Hughes wrote:
diff --git a/dlls/winmm/tests/mmio.c b/dlls/winmm/tests/mmio.c index e3984fbaf3..0de51a2562 100644 --- a/dlls/winmm/tests/mmio.c +++ b/dlls/winmm/tests/mmio.c @@ -478,6 +478,7 @@ static void test_mmioOpen_create(void) WCHAR cwd[MAX_PATH], temp_dir[MAX_PATH]; /* According to docs, filename must be no more than 128 bytes, but it will * actually allow longer than that. */ + WCHAR relpath[] = L"local\\examplefile"; WCHAR filename[] = L"very_long_filename_" L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -520,6 +521,14 @@ static void test_mmioOpen_create(void)
DeleteFileW(filename);
+ CreateDirectoryA("local", NULL); + hmmio = mmioOpenW(relpath, NULL, MMIO_CREATE | MMIO_WRITE | MMIO_EXCLUSIVE); + ok(hmmio != NULL, "mmioOpen failed\n"); + mmioClose(hmmio, 0); + + DeleteFileW(relpath); + RemoveDirectoryA("local"); + SetCurrentDirectoryW(cwd); }
On my machine, this test passes without your changes to <dlls/winmm/mmio.c> applied. This is what I'd expect, CreateFile should find files that are relative to the CWD in the same was as SearchPath, so your patch is a no-op in this test case. I think you want to add a test showing that mmioOpen will open files elsewhere in the system path, or whatever it is that the game is depending on. Andrew
participants (3)
-
Alistair Leslie-Hughes -
Andrew Eikum -
Dmitry Timoshkov