diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c index 74622ad5e08..ac983ffeedd 100644 --- a/dlls/kernel32/profile.c +++ b/dlls/kernel32/profile.c @@ -755,7 +755,7 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access ) TRACE("path: %s\n", debugstr_w(buffer)); hFile = CreateFileW(buffer, GENERIC_READ | (write_access ? GENERIC_WRITE : 0), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ((hFile == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_FILE_NOT_FOUND)) diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c index 2ea39555730..47b1ac1afa2 100644 --- a/dlls/kernel32/tests/profile.c +++ b/dlls/kernel32/tests/profile.c @@ -348,6 +348,27 @@ static void test_profile_existing(void) ok( DeleteFile(testfile2), "delete failed\n" ); } +static void test_profile_delete_on_close() +{ + static CHAR testfile[] = ".\\testwine5.ini"; + HANDLE h; + DWORD size, res; + static const char contents[] = "[" SECTION "]\n" KEY "=123\n"; + + h = CreateFile(testfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, + CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); + ok( WriteFile( h, contents, sizeof contents - 1, &size, NULL ), + "Cannot write test file: %x\n", GetLastError() ); + ok( size == sizeof contents - 1, "Test file: partial write\n"); + + res = GetPrivateProfileInt(SECTION, KEY, 0, testfile); + + ok( res == 123, "Got %d instead of 123\n", res); + + /* This also deletes the file */ + CloseHandle(h); +} + static void create_test_file(LPCSTR name, LPCSTR data, DWORD size) { HANDLE hfile; @@ -615,5 +636,6 @@ START_TEST(profile) test_profile_sections(); test_profile_sections_names(); test_profile_existing(); + test_profile_delete_on_close(); test_GetPrivateProfileString(); }