Commit 94e3477d authored by Alexandre Julliard's avatar Alexandre Julliard

Moved slash conversion to collapse_path, and remove duplicate

backslashes too.
parent 075d6a12
...@@ -323,12 +323,19 @@ ULONG WINAPI RtlDosSearchPath_U(LPCWSTR paths, LPCWSTR search, LPCWSTR ext, ...@@ -323,12 +323,19 @@ ULONG WINAPI RtlDosSearchPath_U(LPCWSTR paths, LPCWSTR search, LPCWSTR ext,
* Helper for RtlGetFullPathName_U. * Helper for RtlGetFullPathName_U.
* Get rid of . and .. components in the path. * Get rid of . and .. components in the path.
*/ */
static inline void collapse_path( WCHAR *path ) static inline void collapse_path( WCHAR *path, UINT mark )
{ {
WCHAR *p, *next; WCHAR *p, *next;
p = path; /* convert every / into a \ */
for (p = path; *p; p++) if (*p == '/') *p = '\\';
/* collapse duplicate backslashes */
next = path + max( 1, mark );
for (p = next; *p; p++) if (*p != '\\' || next[-1] != '\\') *next++ = *p;
*next = 0;
p = path + mark;
while (*p) while (*p)
{ {
if (*p == '.') if (*p == '.')
...@@ -337,28 +344,32 @@ static inline void collapse_path( WCHAR *path ) ...@@ -337,28 +344,32 @@ static inline void collapse_path( WCHAR *path )
{ {
case '\\': /* .\ component */ case '\\': /* .\ component */
next = p + 2; next = p + 2;
while (*next == '\\') next++;
memmove( p, next, (strlenW(next) + 1) * sizeof(WCHAR) ); memmove( p, next, (strlenW(next) + 1) * sizeof(WCHAR) );
continue; continue;
case 0: /* final . */ case 0: /* final . */
while (p > path && p[-1] == '\\') p--; if (p > path + mark) p--;
*p = 0; *p = 0;
continue; continue;
case '.': case '.':
if (p[2] == '\\') /* ..\ component */ if (p[2] == '\\') /* ..\ component */
{ {
next = p + 3; next = p + 3;
while (*next == '\\') next++; if (p > path + mark)
while (p > path && p[-1] == '\\') p--; {
while (p > path && p[-1] != '\\') p--; p--;
while (p > path + mark && p[-1] != '\\') p--;
}
memmove( p, next, (strlenW(next) + 1) * sizeof(WCHAR) ); memmove( p, next, (strlenW(next) + 1) * sizeof(WCHAR) );
continue; continue;
} }
else if (!p[2]) /* final .. */ else if (!p[2]) /* final .. */
{ {
while (p > path && p[-1] == '\\') p--; if (p > path + mark)
while (p > path && p[-1] != '\\') p--; {
while (p > path && p[-1] == '\\') p--; p--;
while (p > path + mark && p[-1] != '\\') p--;
if (p > path + mark) p--;
}
*p = 0; *p = 0;
continue; continue;
} }
...@@ -367,11 +378,10 @@ static inline void collapse_path( WCHAR *path ) ...@@ -367,11 +378,10 @@ static inline void collapse_path( WCHAR *path )
} }
/* skip to the next component */ /* skip to the next component */
while (*p && *p != '\\') p++; while (*p && *p != '\\') p++;
while (*p == '\\') p++; if (*p == '\\') p++;
} }
} }
/****************************************************************** /******************************************************************
* get_full_path_helper * get_full_path_helper
* *
...@@ -382,7 +392,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) ...@@ -382,7 +392,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
{ {
ULONG reqsize = 0, mark = 0, dep = 0, deplen; ULONG reqsize = 0, mark = 0, dep = 0, deplen;
DOS_PATHNAME_TYPE type; DOS_PATHNAME_TYPE type;
LPWSTR p, ins_str = NULL; LPWSTR ins_str = NULL;
LPCWSTR ptr; LPCWSTR ptr;
const UNICODE_STRING* cd; const UNICODE_STRING* cd;
WCHAR tmp[4]; WCHAR tmp[4];
...@@ -524,10 +534,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) ...@@ -524,10 +534,7 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
if (ins_str && ins_str != tmp && ins_str != cd->Buffer) if (ins_str && ins_str != tmp && ins_str != cd->Buffer)
RtlFreeHeap(GetProcessHeap(), 0, ins_str); RtlFreeHeap(GetProcessHeap(), 0, ins_str);
/* convert every / into a \ */ collapse_path( buffer, mark );
for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
collapse_path( buffer + mark );
reqsize = strlenW(buffer) * sizeof(WCHAR); reqsize = strlenW(buffer) * sizeof(WCHAR);
done: done:
......
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