mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Fixed more bugs in GetFullPathName() and SetCurrentDirectory().
svn path=/trunk/; revision=428
This commit is contained in:
parent
bc291ce04e
commit
70b2252a9d
2 changed files with 67 additions and 115 deletions
|
@ -96,15 +96,23 @@ WINBOOL STDCALL SetCurrentDirectoryA(LPCSTR lpPathName)
|
||||||
WCHAR PathNameW[MAX_PATH];
|
WCHAR PathNameW[MAX_PATH];
|
||||||
|
|
||||||
if ( lpPathName == NULL )
|
if ( lpPathName == NULL )
|
||||||
return FALSE;
|
{
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ( lstrlen(lpPathName) > MAX_PATH )
|
if ( lstrlen(lpPathName) > MAX_PATH )
|
||||||
return FALSE;
|
{
|
||||||
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((lpPathName[i])!=0 && i < MAX_PATH)
|
while ((lpPathName[i])!=0 && i < MAX_PATH)
|
||||||
{
|
{
|
||||||
PathNameW[i] = (WCHAR)lpPathName[i];
|
PathNameW[i] = (WCHAR)lpPathName[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
PathNameW[i] = 0;
|
PathNameW[i] = 0;
|
||||||
|
|
||||||
return SetCurrentDirectoryW(PathNameW);
|
return SetCurrentDirectoryW(PathNameW);
|
||||||
|
@ -115,114 +123,65 @@ WINBOOL STDCALL SetCurrentDirectoryW(LPCWSTR lpPathName)
|
||||||
ULONG len;
|
ULONG len;
|
||||||
WCHAR PathName[MAX_PATH];
|
WCHAR PathName[MAX_PATH];
|
||||||
HANDLE hDir;
|
HANDLE hDir;
|
||||||
PWSTR prev, current;
|
|
||||||
|
|
||||||
DPRINT("SetCurrentDirectoryW(lpPathName %w)\n",lpPathName);
|
DPRINT("SetCurrentDirectoryW(lpPathName %w)\n",lpPathName);
|
||||||
|
|
||||||
if (lpPathName == NULL)
|
if (lpPathName == NULL)
|
||||||
return FALSE;
|
{
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
len = lstrlenW(lpPathName);
|
len = lstrlenW(lpPathName);
|
||||||
if (len > MAX_PATH)
|
if (len > MAX_PATH)
|
||||||
return FALSE;
|
{
|
||||||
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
||||||
hDir = CreateFileW(lpPathName,
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetFullPathNameW (lpPathName, MAX_PATH, PathName, NULL))
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_BAD_PATHNAME);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("PathName %w\n",PathName);
|
||||||
|
|
||||||
|
hDir = CreateFileW(PathName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
NULL,
|
NULL,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_DIRECTORY,
|
FILE_ATTRIBUTE_DIRECTORY,
|
||||||
NULL);
|
NULL);
|
||||||
if (hDir == NULL)
|
if (hDir == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DPRINT("Failed to open directory\n");
|
DPRINT("Failed to open directory\n");
|
||||||
return(FALSE);
|
SetLastError(ERROR_BAD_PATHNAME);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hCurrentDirectory != NULL)
|
if (hCurrentDirectory != NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(hCurrentDirectory);
|
CloseHandle(hCurrentDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
hCurrentDirectory = hDir;
|
hCurrentDirectory = hDir;
|
||||||
|
|
||||||
DPRINT("lpPathName %w %x\n",lpPathName,lpPathName);
|
|
||||||
if (wcslen(lpPathName) > 2 &&
|
|
||||||
isalpha(lpPathName[0]) &&
|
|
||||||
lpPathName[1] == ':' )
|
|
||||||
{
|
|
||||||
DPRINT("lpPathName %w\n",lpPathName);
|
|
||||||
|
|
||||||
CurrentDrive = toupper((UCHAR)lpPathName[0]) - 'A';
|
|
||||||
if (!(lpPathName[2] == '\\' && lpPathName[3] == 0 &&
|
|
||||||
DriveDirectoryW[CurrentDrive][0] != 0))
|
|
||||||
{
|
|
||||||
wcscpy(DriveDirectoryW[CurrentDrive],&lpPathName[2]);
|
|
||||||
len = lstrlenW(DriveDirectoryW[CurrentDrive]);
|
|
||||||
if (DriveDirectoryW[CurrentDrive][len-1] != '\\')
|
|
||||||
{
|
|
||||||
DriveDirectoryW[CurrentDrive][len] = '\\';
|
|
||||||
DriveDirectoryW[CurrentDrive][len+1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(TRUE);
|
|
||||||
}
|
|
||||||
if (lpPathName[0] == '\\')
|
|
||||||
{
|
|
||||||
wcscpy(DriveDirectoryW[CurrentDrive],lpPathName);
|
|
||||||
return(TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = GetCurrentDirectoryW(MAX_PATH, PathName);
|
|
||||||
if (PathName[len-1] != '\\')
|
|
||||||
{
|
|
||||||
PathName[len] = '\\';
|
|
||||||
PathName[len+1] = 0;
|
|
||||||
}
|
|
||||||
lstrcatW(PathName, lpPathName);
|
|
||||||
len = lstrlenW(PathName);
|
|
||||||
if (PathName[len-1] != '\\')
|
|
||||||
{
|
|
||||||
PathName[len] = '\\';
|
|
||||||
PathName[len+1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("PathName %w\n",PathName);
|
DPRINT("PathName %w\n",PathName);
|
||||||
|
|
||||||
prev = NULL;
|
CurrentDrive = toupper((UCHAR)PathName[0]) - 'A';
|
||||||
current = &PathName[2];
|
wcscpy(DriveDirectoryW[CurrentDrive],&PathName[2]);
|
||||||
|
len = lstrlenW(DriveDirectoryW[CurrentDrive]);
|
||||||
while (current != NULL)
|
if (DriveDirectoryW[CurrentDrive][len-1] != '\\')
|
||||||
{
|
{
|
||||||
if (current[1] == '.' && current[2] == '\\')
|
DriveDirectoryW[CurrentDrive][len] = '\\';
|
||||||
{
|
DriveDirectoryW[CurrentDrive][len+1] = 0;
|
||||||
wcscpy(current, current+2);
|
|
||||||
}
|
|
||||||
else if (current[1] == '.' && current[2] == '.' &&
|
|
||||||
current[3] == '\\' && prev != NULL)
|
|
||||||
{
|
|
||||||
wcscpy(prev, current+3);
|
|
||||||
current = prev;
|
|
||||||
while (prev > PathName && (*prev) != '\\')
|
|
||||||
{
|
|
||||||
prev--;
|
|
||||||
}
|
|
||||||
if (prev == PathName)
|
|
||||||
{
|
|
||||||
prev = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prev = current;
|
|
||||||
current = wcschr(current+1, (WCHAR)'\\');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lstrcpyW(DriveDirectoryW[CurrentDrive], &PathName[2]);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DWORD STDCALL GetTempPathA(DWORD nBufferLength, LPSTR lpBuffer)
|
DWORD STDCALL GetTempPathA(DWORD nBufferLength, LPSTR lpBuffer)
|
||||||
{
|
{
|
||||||
WCHAR BufferW[MAX_PATH];
|
WCHAR BufferW[MAX_PATH];
|
||||||
|
@ -237,7 +196,6 @@ DWORD STDCALL GetTempPathA(DWORD nBufferLength, LPSTR lpBuffer)
|
||||||
}
|
}
|
||||||
lpBuffer[i] = 0;
|
lpBuffer[i] = 0;
|
||||||
return retCode;
|
return retCode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD STDCALL GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer)
|
DWORD STDCALL GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer)
|
||||||
|
@ -305,8 +263,7 @@ GetSystemDirectoryW(
|
||||||
uPathSize = lstrlenW(SystemDirectoryW);
|
uPathSize = lstrlenW(SystemDirectoryW);
|
||||||
if ( uSize > uPathSize )
|
if ( uSize > uPathSize )
|
||||||
lstrcpynW(lpBuffer,SystemDirectoryW,uPathSize);
|
lstrcpynW(lpBuffer,SystemDirectoryW,uPathSize);
|
||||||
|
|
||||||
|
|
||||||
return uPathSize;
|
return uPathSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,8 +280,7 @@ GetWindowsDirectoryW(
|
||||||
uPathSize = lstrlenW(WindowsDirectoryW);
|
uPathSize = lstrlenW(WindowsDirectoryW);
|
||||||
if ( uSize > uPathSize );
|
if ( uSize > uPathSize );
|
||||||
lstrcpynW(lpBuffer,WindowsDirectoryW,uPathSize);
|
lstrcpynW(lpBuffer,WindowsDirectoryW,uPathSize);
|
||||||
|
|
||||||
return uPathSize;
|
return uPathSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -189,8 +189,8 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
|
||||||
PSTR p;
|
PSTR p;
|
||||||
PSTR prev = NULL;
|
PSTR prev = NULL;
|
||||||
|
|
||||||
DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %s, "
|
DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
|
||||||
"lpFilePart %x)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
|
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
|
||||||
|
|
||||||
if (!lpFileName || !lpBuffer)
|
if (!lpFileName || !lpBuffer)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -236,8 +236,9 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
|
||||||
DPRINT("lpBuffer %s\n",lpBuffer);
|
DPRINT("lpBuffer %s\n",lpBuffer);
|
||||||
|
|
||||||
p = lpBuffer + 2;
|
p = lpBuffer + 2;
|
||||||
|
prev = p;
|
||||||
|
|
||||||
while ((*p) != 0)
|
while ((*p) != 0 || ((*p) == '\\' && (*(p+1)) == 0))
|
||||||
{
|
{
|
||||||
DWORD dwDotLen;
|
DWORD dwDotLen;
|
||||||
|
|
||||||
|
@ -264,23 +265,20 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
|
||||||
{
|
{
|
||||||
int n = dwDotLen - 2;
|
int n = dwDotLen - 2;
|
||||||
|
|
||||||
while (n > 0)
|
while (n > 0 && prev > (lpBuffer+2))
|
||||||
{
|
{
|
||||||
prev--;
|
prev--;
|
||||||
if ((*prev) == '\\')
|
if ((*prev) == '\\')
|
||||||
n--;
|
n--;
|
||||||
if (prev == (lpBuffer+2))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lstrcpyA (prev, p+dwDotLen+1);
|
if (*(p+dwDotLen+1) == 0)
|
||||||
p = prev;
|
*(prev+1) = 0;
|
||||||
if (prev == (lpBuffer+2))
|
|
||||||
{
|
|
||||||
prev = NULL;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
lstrcpyA (prev, p+dwDotLen+1);
|
||||||
|
p = prev;
|
||||||
|
if (prev > (lpBuffer+2))
|
||||||
{
|
{
|
||||||
prev--;
|
prev--;
|
||||||
while ((*prev) != '\\')
|
while ((*prev) != '\\')
|
||||||
|
@ -328,8 +326,8 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
|
||||||
PWSTR p;
|
PWSTR p;
|
||||||
PWSTR prev = NULL;
|
PWSTR prev = NULL;
|
||||||
|
|
||||||
DPRINT("GetFullPathNameW(lpFileName %w, nBufferLength %d, lpBuffer %w, "
|
DPRINT("GetFullPathNameW(lpFileName %w, nBufferLength %d, lpBuffer %p, "
|
||||||
"lpFilePart %x)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
|
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
|
||||||
|
|
||||||
if (!lpFileName || !lpBuffer)
|
if (!lpFileName || !lpBuffer)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -375,8 +373,9 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
|
||||||
DPRINT("lpBuffer %w\n",lpBuffer);
|
DPRINT("lpBuffer %w\n",lpBuffer);
|
||||||
|
|
||||||
p = lpBuffer + 2;
|
p = lpBuffer + 2;
|
||||||
|
prev = p;
|
||||||
|
|
||||||
while ((*p) != 0)
|
while ((*p) != 0 || ((*p) == L'\\' && (*(p+1)) == 0))
|
||||||
{
|
{
|
||||||
DWORD dwDotLen;
|
DWORD dwDotLen;
|
||||||
|
|
||||||
|
@ -403,23 +402,20 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
|
||||||
{
|
{
|
||||||
int n = dwDotLen - 2;
|
int n = dwDotLen - 2;
|
||||||
|
|
||||||
while (n > 0)
|
while (n > 0 && prev > (lpBuffer+2))
|
||||||
{
|
{
|
||||||
prev--;
|
prev--;
|
||||||
if ((*prev) == L'\\')
|
if ((*prev) == L'\\')
|
||||||
n--;
|
n--;
|
||||||
if (prev == (lpBuffer+2))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lstrcpyW (prev, p+dwDotLen+1);
|
if (*(p+dwDotLen+1) == 0)
|
||||||
p = prev;
|
*(prev+1) = 0;
|
||||||
if (prev == (lpBuffer+2))
|
|
||||||
{
|
|
||||||
prev = NULL;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
lstrcpyW (prev, p+dwDotLen+1);
|
||||||
|
p = prev;
|
||||||
|
if (prev > (lpBuffer+2))
|
||||||
{
|
{
|
||||||
prev--;
|
prev--;
|
||||||
while ((*prev) != L'\\')
|
while ((*prev) != L'\\')
|
||||||
|
|
Loading…
Reference in a new issue