Commit 017438cd authored by Alexandre Julliard's avatar Alexandre Julliard

Fixed handling of \\?\ prefix in RtlDosPathNameToNtPathName_U.

Fixed parsing of UNC file names in RtlGetFullPathName_U.
parent 1a833442
...@@ -301,7 +301,7 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path, ...@@ -301,7 +301,7 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path,
CURDIR* cd) CURDIR* cd)
{ {
static const WCHAR LongFileNamePfxW[4] = {'\\','\\','?','\\'}; static const WCHAR LongFileNamePfxW[4] = {'\\','\\','?','\\'};
ULONG sz, ptr_sz, offset; ULONG sz, offset;
WCHAR local[MAX_PATH]; WCHAR local[MAX_PATH];
LPWSTR ptr; LPWSTR ptr;
...@@ -316,20 +316,21 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path, ...@@ -316,20 +316,21 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path,
if (!dos_path || !*dos_path) return FALSE; if (!dos_path || !*dos_path) return FALSE;
if (!memcmp(dos_path, LongFileNamePfxW, sizeof(LongFileNamePfxW))) if (!strncmpW(dos_path, LongFileNamePfxW, 4))
{ {
dos_path += sizeof(LongFileNamePfxW) / sizeof(WCHAR); ntpath->Length = strlenW(dos_path) * sizeof(WCHAR);
ptr = NULL; ntpath->MaximumLength = ntpath->Length + sizeof(WCHAR);
ptr_sz = 0; ntpath->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, ntpath->MaximumLength);
} if (!ntpath->Buffer) return FALSE;
else memcpy( ntpath->Buffer, dos_path, ntpath->MaximumLength );
{ ntpath->Buffer[1] = '?'; /* change \\?\ to \??\ */
ptr = local; return TRUE;
ptr_sz = sizeof(local);
} }
sz = RtlGetFullPathName_U(dos_path, ptr_sz, ptr, file_part);
ptr = local;
sz = RtlGetFullPathName_U(dos_path, sizeof(local), ptr, file_part);
if (sz == 0) return FALSE; if (sz == 0) return FALSE;
if (sz > ptr_sz) if (sz > sizeof(local))
{ {
ptr = RtlAllocateHeap(GetProcessHeap(), 0, sz); ptr = RtlAllocateHeap(GetProcessHeap(), 0, sz);
sz = RtlGetFullPathName_U(dos_path, sz, ptr, file_part); sz = RtlGetFullPathName_U(dos_path, sz, ptr, file_part);
...@@ -348,16 +349,14 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path, ...@@ -348,16 +349,14 @@ BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path,
switch (RtlDetermineDosPathNameType_U(ptr)) switch (RtlDetermineDosPathNameType_U(ptr))
{ {
case UNC_PATH: /* \\foo */ case UNC_PATH: /* \\foo */
if (ptr[2] != '?') offset = 2;
{ strcatW(ntpath->Buffer, UncPfxW);
offset = 2;
strcatW(ntpath->Buffer, UncPfxW);
}
break; break;
case DEVICE_PATH: /* \\.\foo */ case DEVICE_PATH: /* \\.\foo */
offset = 4; offset = 4;
break; break;
default: break; /* needed to keep gcc quiet */ default:
break; /* needed to keep gcc quiet */
} }
strcatW(ntpath->Buffer, ptr + offset); strcatW(ntpath->Buffer, ptr + offset);
...@@ -508,6 +507,23 @@ static inline void collapse_path( WCHAR *path, UINT mark ) ...@@ -508,6 +507,23 @@ static inline void collapse_path( WCHAR *path, UINT mark )
} }
} }
/******************************************************************
* skip_unc_prefix
*
* Skip the \\share\dir\ part of a file name. Helper for RtlGetFullPathName_U.
*/
static const WCHAR *skip_unc_prefix( const WCHAR *ptr )
{
ptr += 2;
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* share name */
while (IS_SEPARATOR(*ptr)) ptr++;
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* dir name */
while (IS_SEPARATOR(*ptr)) ptr++;
return ptr;
}
/****************************************************************** /******************************************************************
* get_full_path_helper * get_full_path_helper
* *
...@@ -530,10 +546,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) ...@@ -530,10 +546,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
switch (type = RtlDetermineDosPathNameType_U(name)) switch (type = RtlDetermineDosPathNameType_U(name))
{ {
case UNC_PATH: /* \\foo */ case UNC_PATH: /* \\foo */
ptr = name + 2; ptr = skip_unc_prefix( name );
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* share name */
while (*ptr && IS_SEPARATOR(*ptr)) ptr++;
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* dir name */
mark = (ptr - name); mark = (ptr - name);
break; break;
...@@ -601,9 +614,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) ...@@ -601,9 +614,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
ins_str = cd->Buffer; ins_str = cd->Buffer;
if (cd->Buffer[1] != ':') if (cd->Buffer[1] != ':')
{ {
ptr = strchrW(cd->Buffer + 2, '\\'); ptr = skip_unc_prefix( cd->Buffer );
if (ptr) ptr = strchrW(ptr + 1, '\\');
if (!ptr) ptr = cd->Buffer + strlenW(cd->Buffer);
mark = ptr - cd->Buffer; mark = ptr - cd->Buffer;
} }
else mark = 3; else mark = 3;
...@@ -636,9 +647,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) ...@@ -636,9 +647,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
} }
else else
{ {
ptr = strchrW(cd->Buffer + 2, '\\'); ptr = skip_unc_prefix( cd->Buffer );
if (ptr) ptr = strchrW(ptr + 1, '\\');
if (!ptr) ptr = cd->Buffer + strlenW(cd->Buffer);
reqsize = (ptr - cd->Buffer) * sizeof(WCHAR); reqsize = (ptr - cd->Buffer) * sizeof(WCHAR);
mark = reqsize / sizeof(WCHAR); mark = reqsize / sizeof(WCHAR);
ins_str = cd->Buffer; ins_str = cd->Buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment