From: yaoyongjie yaoyongjie@uniontech.com
In DeleteFile functions, by default, the file name and path are limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, need prepend "\\?\" to the path. --- dlls/kernel32/tests/file.c | 20 ++++++++++---------- dlls/kernelbase/file.c | 6 ++++++ 2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index da4fd8d4ec8..797834a63ab 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -1054,9 +1054,9 @@ static void test_CopyFileW(void) ret = CopyFileExW(long_path_1, long_path_2, NULL, NULL, NULL, 0); ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND, "Expected CopyFileExW failed with ERROR_PATH_NOT_FOUND, but got %ld, copy %s -> %s\n", GetLastError(), wine_dbgstr_w(long_path_1), wine_dbgstr_w(long_path_2)); ret = DeleteFileW(long_path_1); - todo_wine ok(!ret, "Unexpected DeleteFileW successed\n"); + ok(!ret, "Unexpected DeleteFileW successed\n"); ret = DeleteFileW(long_path_2); - todo_wine ok(!ret, "Unexpected DeleteFileW successed\n"); + ok(!ret, "Unexpected DeleteFileW successed\n"); }
/* test long file name prepend "\?" */ @@ -1078,35 +1078,35 @@ static void test_CopyFileW(void) wcscpy(long_path_1, temp_path); wcscat(long_path_1, long_name_1); ret = DeleteFileW(long_path_1); - todo_wine ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); wcscpy(long_path_2, temp_path); wcscat(long_path_2, long_name_2); ret = DeleteFileW(long_path_2); - todo_wine ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); } else { wcscpy(long_path_1, temp_path); wcscat(long_path_1, long_name_1); ret = DeleteFileW(long_path_1); - todo_wine ok(!ret, "Unexpected DeleteFileW successed, %s\n", wine_dbgstr_w(long_path_1)); + ok(!ret, "Unexpected DeleteFileW successed, %s\n", wine_dbgstr_w(long_path_1)); wcscpy(long_path_2, temp_path); wcscat(long_path_2, long_name_2); ret = DeleteFileW(long_path_2); - todo_wine ok(!ret, "Unexpected DeleteFileW successed, %s\n", wine_dbgstr_w(long_path_1)); + ok(!ret, "Unexpected DeleteFileW successed, %s\n", wine_dbgstr_w(long_path_1));
wcscpy(long_path_1, L"\\?\"); wcscat(long_path_1, temp_path); wcscat(long_path_1, long_name_1); SetLastError(0xdeadbeef); ret = DeleteFileW(long_path_1); - todo_wine ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); wcscpy(long_path_2, L"\\?\"); wcscat(long_path_2, temp_path); wcscat(long_path_2, long_name_2); SetLastError(0xdeadbeef); ret = DeleteFileW(long_path_2); - todo_wine ok(ret, "DeleteFileW: error %ld\n", GetLastError()); + ok(ret, "DeleteFileW: error %ld\n", GetLastError()); }
ret = DeleteFileW(source); @@ -1474,11 +1474,11 @@ static void test_CopyFileEx(void) strcpy(long_path_1, temp_path); strcat(long_path_1, long_name_1); ret = DeleteFileA(long_path_1); - todo_wine ok(!ret, "Unexpected DeleteFileA successed, %s\n", long_path_1); + ok(!ret, "Unexpected DeleteFileA successed, %s\n", long_path_1); strcpy(long_path_2, temp_path); strcat(long_path_2, long_name_2); ret = DeleteFileA(long_path_2); - todo_wine ok(!ret, "Unexpected DeleteFileA successed, %s\n", long_path_2); + ok(!ret, "Unexpected DeleteFileA successed, %s\n", long_path_2);
strcpy(long_path_1, "\\?\"); strcat(long_path_1, temp_path); diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index 6db871c9483..77ac5841a71 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -1081,6 +1081,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH DeleteFileW( LPCWSTR path )
TRACE( "%s\n", debugstr_w(path) );
+ if (path && !is_longpath_enabled() && wcsncmp(path, L"\\?\", 4) && wcslen(path) >= MAX_PATH ) + { + SetLastError( ERROR_PATH_NOT_FOUND ); + return FALSE; + } + if (!RtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL )) { SetLastError( ERROR_PATH_NOT_FOUND );