From: Zebediah Figura Subject: [PATCH v3 4/4] winmm: Search the default path when opening an existing file in create_file_OF(). Message-Id: <20201217224051.703838-4-z.figura12@gmail.com> Date: Thu, 17 Dec 2020 16:40:51 -0600 In-Reply-To: <20201217224051.703838-1-z.figura12@gmail.com> References: <20201217224051.703838-1-z.figura12@gmail.com> Based on a patch by Alistair Leslie-Hughes. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49650 Signed-off-by: Zebediah Figura --- dlls/winmm/mmio.c | 24 ++++++++++++++++++++++-- dlls/winmm/tests/mmio.c | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index cb3175c5cd7..da536357416 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -51,7 +51,9 @@ static WINE_MMIO *MMIOList; /* From kernel32 */ static HANDLE create_file_OF( LPCSTR path, INT mode ) { - DWORD access, sharing, creation; + DWORD access, sharing, creation, len; + char *full_path; + HANDLE ret; if (mode & OF_CREATE) { @@ -79,7 +81,25 @@ 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 ); + + if (mode & OF_CREATE) + return CreateFileA( path, access, sharing, NULL, creation, FILE_ATTRIBUTE_NORMAL, 0 ); + + if (!(len = SearchPathA( NULL, path, NULL, 0, NULL, NULL ))) + return INVALID_HANDLE_VALUE; + if (!(full_path = malloc(len + 1))) + { + SetLastError( ERROR_OUTOFMEMORY ); + return INVALID_HANDLE_VALUE; + } + if (!SearchPathA( NULL, path, NULL, len + 1, full_path, NULL )) + { + free(full_path); + return INVALID_HANDLE_VALUE; + } + ret = CreateFileA( full_path, access, sharing, NULL, creation, FILE_ATTRIBUTE_NORMAL, 0 ); + free(full_path); + return ret; } /************************************************************************** diff --git a/dlls/winmm/tests/mmio.c b/dlls/winmm/tests/mmio.c index c9ceda24f3f..a232070064c 100644 --- a/dlls/winmm/tests/mmio.c +++ b/dlls/winmm/tests/mmio.c @@ -551,7 +551,7 @@ static void test_mmioOpen_create(void) wcscpy(buffer, L"test_mmio_path"); hmmio = mmioOpenW(buffer, &info, MMIO_WRITE); - todo_wine ok(!!hmmio, "failed to open file, error %#x\n", info.wErrorRet); + ok(!!hmmio, "failed to open file, error %#x\n", info.wErrorRet); mmioClose(hmmio, 0); wcscpy(buffer, L"test_mmio_path"); -- 2.29.2