Handle \path\ending\in\slash\ directory searches

svn path=/trunk/; revision=6942
This commit is contained in:
Gé van Geldorp 2003-12-09 23:37:59 +00:00
parent 2f434abd37
commit 2989352879

View file

@ -1,4 +1,4 @@
/* $Id: find.c,v 1.40 2003/11/17 02:12:50 hyperion Exp $ /* $Id: find.c,v 1.41 2003/12/09 23:37:59 gvg Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -96,6 +96,7 @@ InternalFindFirstFile (
NTSTATUS Status; NTSTATUS Status;
PWSTR e1, e2; PWSTR e1, e2;
WCHAR CurrentDir[256]; WCHAR CurrentDir[256];
PWCHAR SlashlessFileName;
PWSTR SearchPath; PWSTR SearchPath;
PWCHAR SearchPattern; PWCHAR SearchPattern;
ULONG Length; ULONG Length;
@ -104,6 +105,26 @@ InternalFindFirstFile (
DPRINT("FindFirstFileW(lpFileName %S)\n", DPRINT("FindFirstFileW(lpFileName %S)\n",
lpFileName); lpFileName);
Length = wcslen(lpFileName);
if (L'\\' == lpFileName[Length - 1])
{
SlashlessFileName = RtlAllocateHeap(hProcessHeap,
0,
Length * sizeof(WCHAR));
if (NULL == SlashlessFileName)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
memcpy(SlashlessFileName, lpFileName, (Length - 1) * sizeof(WCHAR));
SlashlessFileName[Length - 1] = L'\0';
lpFileName = SlashlessFileName;
}
else
{
SlashlessFileName = NULL;
}
e1 = wcsrchr(lpFileName, L'/'); e1 = wcsrchr(lpFileName, L'/');
e2 = wcsrchr(lpFileName, L'\\'); e2 = wcsrchr(lpFileName, L'\\');
SearchPattern = max(e1, e2); SearchPattern = max(e1, e2);
@ -116,6 +137,12 @@ InternalFindFirstFile (
Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath); Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath);
if (0 == Length) if (0 == Length)
{ {
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
return NULL; return NULL;
} }
if (Length > sizeof(CurrentDir) / sizeof(WCHAR)) if (Length > sizeof(CurrentDir) / sizeof(WCHAR))
@ -125,6 +152,12 @@ InternalFindFirstFile (
Length * sizeof(WCHAR)); Length * sizeof(WCHAR));
if (NULL == SearchPath) if (NULL == SearchPath)
{ {
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL; return NULL;
} }
@ -143,6 +176,12 @@ InternalFindFirstFile (
(Length + 1) * sizeof(WCHAR)); (Length + 1) * sizeof(WCHAR));
if (NULL == SearchPath) if (NULL == SearchPath)
{ {
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL; return NULL;
} }
@ -163,6 +202,12 @@ InternalFindFirstFile (
} }
if (FALSE == bResult) if (FALSE == bResult)
{ {
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
return NULL; return NULL;
} }
@ -176,6 +221,12 @@ InternalFindFirstFile (
RtlFreeHeap (hProcessHeap, RtlFreeHeap (hProcessHeap,
0, 0,
NtPathU.Buffer); NtPathU.Buffer);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL; return NULL;
} }
@ -213,6 +264,12 @@ InternalFindFirstFile (
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeHeap (hProcessHeap, 0, IData); RtlFreeHeap (hProcessHeap, 0, IData);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return(NULL); return(NULL);
} }
@ -230,6 +287,12 @@ InternalFindFirstFile (
TRUE, TRUE,
&PatternStr, &PatternStr,
TRUE); TRUE);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Status %lx\n", Status); DPRINT("Status %lx\n", Status);