Author: pschweitzer
Date: Sat Feb 26 17:18:21 2011
New Revision: 50913
URL:
http://svn.reactos.org/svn/reactos?rev=50913&view=rev
Log:
[KERNEL32]
Start unifying kernel32 Find* functions.
All calls end in same methods that are working only in unicode now.
Next step would be to unify stream & files using only one struct.
Modified:
trunk/reactos/dll/win32/kernel32/file/find.c
Modified: trunk/reactos/dll/win32/kernel32/file/find.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/fi…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/find.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/file/find.c [iso-8859-1] Sat Feb 26 17:18:21 2011
@@ -5,6 +5,7 @@
* FILE: lib/kernel32/file/find.c
* PURPOSE: Find functions
* PROGRAMMER: Ariadne ( ariadne(a)xs4all.nl)
+ * Pierre Schweitzer (pierre.schweitzer(a)reactos.org)
* UPDATE HISTORY:
* Created 01/11/98
*/
@@ -74,34 +75,6 @@
}
static VOID
-InternalCopyDeviceFindDataA(LPWIN32_FIND_DATAA lpFindFileData,
- PUNICODE_STRING FileName,
- ULONG DeviceNameInfo)
-{
- UNICODE_STRING DeviceName;
- ANSI_STRING BufferA;
- CHAR Buffer[MAX_PATH];
-
- DeviceName.Length = DeviceName.MaximumLength = (USHORT)(DeviceNameInfo &
0xFFFF);
- DeviceName.Buffer = (LPWSTR)((ULONG_PTR)FileName->Buffer + (DeviceNameInfo
>> 16));
-
- BufferA.MaximumLength = sizeof(Buffer) - sizeof(Buffer[0]);
- BufferA.Buffer = Buffer;
- if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&BufferA, &DeviceName, FALSE);
- else
- RtlUnicodeStringToOemString (&BufferA, &DeviceName, FALSE);
-
- /* Return the data */
- RtlZeroMemory(lpFindFileData,
- sizeof(*lpFindFileData));
- lpFindFileData->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
- RtlCopyMemory(lpFindFileData->cFileName,
- BufferA.Buffer,
- BufferA.Length);
-}
-
-static VOID
InternalCopyFindDataW(LPWIN32_FIND_DATAW lpFindFileData,
PFILE_BOTH_DIR_INFORMATION lpFileInfo)
{
@@ -126,57 +99,6 @@
lpFindFileData->cAlternateFileName[lpFileInfo->ShortNameLength / sizeof(WCHAR)]
= 0;
}
-static VOID
-InternalCopyFindDataA(LPWIN32_FIND_DATAA lpFindFileData,
- PFILE_BOTH_DIR_INFORMATION lpFileInfo)
-{
- UNICODE_STRING FileNameU;
- ANSI_STRING FileNameA;
-
- lpFindFileData->dwFileAttributes = lpFileInfo->FileAttributes;
-
- lpFindFileData->ftCreationTime.dwHighDateTime =
lpFileInfo->CreationTime.u.HighPart;
- lpFindFileData->ftCreationTime.dwLowDateTime =
lpFileInfo->CreationTime.u.LowPart;
-
- lpFindFileData->ftLastAccessTime.dwHighDateTime =
lpFileInfo->LastAccessTime.u.HighPart;
- lpFindFileData->ftLastAccessTime.dwLowDateTime =
lpFileInfo->LastAccessTime.u.LowPart;
-
- lpFindFileData->ftLastWriteTime.dwHighDateTime =
lpFileInfo->LastWriteTime.u.HighPart;
- lpFindFileData->ftLastWriteTime.dwLowDateTime =
lpFileInfo->LastWriteTime.u.LowPart;
-
- lpFindFileData->nFileSizeHigh = lpFileInfo->EndOfFile.u.HighPart;
- lpFindFileData->nFileSizeLow = lpFileInfo->EndOfFile.u.LowPart;
-
- FileNameU.Length = FileNameU.MaximumLength = (USHORT)lpFileInfo->FileNameLength;
- FileNameU.Buffer = lpFileInfo->FileName;
-
- FileNameA.MaximumLength = sizeof(lpFindFileData->cFileName) - sizeof(CHAR);
- FileNameA.Buffer = lpFindFileData->cFileName;
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&FileNameA, &FileNameU, FALSE);
- else
- RtlUnicodeStringToOemString (&FileNameA, &FileNameU, FALSE);
-
- FileNameA.Buffer[FileNameA.Length] = 0;
-
- TRACE("lpFileInfo->ShortNameLength %d\n",
lpFileInfo->ShortNameLength);
-
- FileNameU.Length = FileNameU.MaximumLength = lpFileInfo->ShortNameLength;
- FileNameU.Buffer = lpFileInfo->ShortName;
-
- FileNameA.MaximumLength = sizeof(lpFindFileData->cAlternateFileName) -
sizeof(CHAR);
- FileNameA.Buffer = lpFindFileData->cAlternateFileName;
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&FileNameA, &FileNameU, FALSE);
- else
- RtlUnicodeStringToOemString (&FileNameA, &FileNameU, FALSE);
-
- FileNameA.Buffer[FileNameA.Length] = 0;
-}
/*
* @implemented
@@ -186,8 +108,7 @@
InternalFindNextFile (
HANDLE hFindFile,
PUNICODE_STRING SearchPattern,
- PVOID lpFindFileData,
- BOOL bUnicode
+ PVOID lpFindFileData
)
{
PKERNEL32_FIND_DATA_HEADER IHeader;
@@ -290,16 +211,8 @@
{
_SEH2_TRY
{
- if (bUnicode)
- {
- InternalCopyFindDataW(lpFindFileData,
- FoundFile);
- }
- else
- {
- InternalCopyFindDataA(lpFindFileData,
- FoundFile);
- }
+ InternalCopyFindDataW(lpFindFileData,
+ FoundFile);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -334,8 +247,7 @@
InternalFindFirstFile (
LPCWSTR lpFileName,
BOOLEAN DirectoryOnly,
- PVOID lpFindFileData,
- BOOL bUnicode
+ PVOID lpFindFileData
)
{
OBJECT_ATTRIBUTES ObjectAttributes;
@@ -460,18 +372,9 @@
DeviceNameInfo = RtlIsDosDeviceName_U((PWSTR)((ULONG_PTR)lpFileName));
if (DeviceNameInfo != 0)
{
- if (bUnicode)
- {
- InternalCopyDeviceFindDataW(lpFindFileData,
- lpFileName,
- DeviceNameInfo);
- }
- else
- {
- InternalCopyDeviceFindDataA(lpFindFileData,
- &FileName,
- DeviceNameInfo);
- }
+ InternalCopyDeviceFindDataW(lpFindFileData,
+ lpFileName,
+ DeviceNameInfo);
return FIND_DEVICE_HANDLE;
}
@@ -526,8 +429,7 @@
bResult = InternalFindNextFile((HANDLE)IHeader,
&PathFileName,
- lpFindFileData,
- bUnicode);
+ lpFindFileData);
RtlFreeHeap (hProcessHeap,
0,
@@ -551,17 +453,59 @@
*/
HANDLE
WINAPI
-FindFirstFileA (
- LPCSTR lpFileName,
- LPWIN32_FIND_DATAA lpFindFileData
- )
-{
- return FindFirstFileExA (lpFileName,
- FindExInfoStandard,
- (LPVOID)lpFindFileData,
- FindExSearchNameMatch,
- NULL,
- 0);
+FindFirstFileA(IN LPCSTR lpFileName,
+ OUT LPWIN32_FIND_DATAA lpFindFileData)
+{
+ HANDLE hSearch;
+ NTSTATUS Status;
+ ANSI_STRING Ansi;
+ UNICODE_STRING UTF8;
+ PUNICODE_STRING lpFileNameW;
+ WIN32_FIND_DATAW FindFileDataW;
+
+ lpFileNameW = Basep8BitStringToStaticUnicodeString(lpFileName);
+ if (!lpFileNameW)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ hSearch = FindFirstFileExW(lpFileNameW->Buffer,
+ FindExInfoStandard,
+ &FindFileDataW,
+ FindExSearchNameMatch,
+ NULL, 0);
+ if (hSearch == INVALID_HANDLE_VALUE)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ memcpy(lpFindFileData, &FindFileDataW, FIELD_OFFSET(WIN32_FIND_DATA,
cFileName));
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cFileName);
+ Ansi.Buffer = lpFindFileData->cFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = MAX_PATH;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ FindClose(hSearch);
+ BaseSetLastNTError(Status);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cAlternateFileName);
+ Ansi.Buffer = lpFindFileData->cAlternateFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = 14;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ FindClose(hSearch);
+ BaseSetLastNTError(Status);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ return hSearch;
}
@@ -570,14 +514,44 @@
*/
BOOL
WINAPI
-FindNextFileA (
- HANDLE hFindFile,
- LPWIN32_FIND_DATAA lpFindFileData)
-{
- return InternalFindNextFile (hFindFile,
- NULL,
- lpFindFileData,
- FALSE);
+FindNextFileA(IN HANDLE hFindFile,
+ OUT LPWIN32_FIND_DATAA lpFindFileData)
+{
+ NTSTATUS Status;
+ ANSI_STRING Ansi;
+ UNICODE_STRING UTF8;
+ WIN32_FIND_DATAW FindFileDataW;
+
+ if (!FindNextFileW(hFindFile, &FindFileDataW))
+ {
+ return FALSE;
+ }
+
+ memcpy(lpFindFileData, &FindFileDataW, FIELD_OFFSET(WIN32_FIND_DATA,
cFileName));
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cFileName);
+ Ansi.Buffer = lpFindFileData->cFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = MAX_PATH;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return FALSE;
+ }
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cAlternateFileName);
+ Ansi.Buffer = lpFindFileData->cAlternateFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = 14;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return FALSE;
+ }
+
+ return TRUE;
}
@@ -643,17 +617,15 @@
*/
HANDLE
WINAPI
-FindFirstFileW (
- LPCWSTR lpFileName,
- LPWIN32_FIND_DATAW lpFindFileData
- )
-{
- return FindFirstFileExW (lpFileName,
- FindExInfoStandard,
- (LPVOID)lpFindFileData,
- FindExSearchNameMatch,
- NULL,
- 0);
+FindFirstFileW(IN LPCWSTR lpFileName,
+ OUT LPWIN32_FIND_DATAW lpFindFileData)
+{
+ return FindFirstFileExW(lpFileName,
+ FindExInfoStandard,
+ lpFindFileData,
+ FindExSearchNameMatch,
+ NULL,
+ 0);
}
/*
@@ -661,15 +633,12 @@
*/
BOOL
WINAPI
-FindNextFileW (
- HANDLE hFindFile,
- LPWIN32_FIND_DATAW lpFindFileData
- )
-{
- return InternalFindNextFile (hFindFile,
- NULL,
- lpFindFileData,
- TRUE);
+FindNextFileW(IN HANDLE hFindFile,
+ OUT LPWIN32_FIND_DATAW lpFindFileData)
+{
+ return InternalFindNextFile(hFindFile,
+ NULL,
+ lpFindFileData);
}
@@ -678,12 +647,12 @@
*/
HANDLE
WINAPI
-FindFirstFileExW (LPCWSTR lpFileName,
- FINDEX_INFO_LEVELS fInfoLevelId,
- LPVOID lpFindFileData,
- FINDEX_SEARCH_OPS fSearchOp,
- LPVOID lpSearchFilter,
- DWORD dwAdditionalFlags)
+FindFirstFileExW(IN LPCWSTR lpFileName,
+ IN FINDEX_INFO_LEVELS fInfoLevelId,
+ OUT LPVOID lpFindFileData,
+ IN FINDEX_SEARCH_OPS fSearchOp,
+ LPVOID lpSearchFilter,
+ IN DWORD dwAdditionalFlags)
{
if (fInfoLevelId != FindExInfoStandard)
{
@@ -701,8 +670,7 @@
return InternalFindFirstFile (lpFileName,
fSearchOp == FindExSearchLimitToDirectories,
- lpFindFileData,
- TRUE);
+ lpFindFileData);
}
SetLastError(ERROR_INVALID_PARAMETER);
@@ -714,51 +682,64 @@
*/
HANDLE
WINAPI
-FindFirstFileExA (
- LPCSTR lpFileName,
- FINDEX_INFO_LEVELS fInfoLevelId,
- LPVOID lpFindFileData,
- FINDEX_SEARCH_OPS fSearchOp,
- LPVOID lpSearchFilter,
- DWORD dwAdditionalFlags
- )
-{
- UNICODE_STRING FileNameU;
- ANSI_STRING FileNameA;
- HANDLE Handle;
-
- if (fInfoLevelId != FindExInfoStandard)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return INVALID_HANDLE_VALUE;
- }
- if (fSearchOp == FindExSearchNameMatch || fSearchOp ==
FindExSearchLimitToDirectories)
- {
- if (lpSearchFilter)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return INVALID_HANDLE_VALUE;
- }
-
- RtlInitAnsiString (&FileNameA, (LPSTR)lpFileName);
-
- /* convert ansi (or oem) string to unicode */
- if (bIsFileApiAnsi)
- RtlAnsiStringToUnicodeString (&FileNameU, &FileNameA, TRUE);
- else
- RtlOemStringToUnicodeString (&FileNameU, &FileNameA, TRUE);
-
- Handle = InternalFindFirstFile (FileNameU.Buffer,
- fSearchOp == FindExSearchLimitToDirectories,
- lpFindFileData,
- FALSE);
-
- RtlFreeUnicodeString (&FileNameU);
- return Handle;
- }
-
- SetLastError(ERROR_INVALID_PARAMETER);
- return INVALID_HANDLE_VALUE;
+FindFirstFileExA(IN LPCSTR lpFileName,
+ IN FINDEX_INFO_LEVELS fInfoLevelId,
+ OUT LPVOID lpFindFileData,
+ IN FINDEX_SEARCH_OPS fSearchOp,
+ LPVOID lpSearchFilter,
+ IN DWORD dwAdditionalFlags)
+{
+ HANDLE hSearch;
+ NTSTATUS Status;
+ ANSI_STRING Ansi;
+ UNICODE_STRING UTF8;
+ PUNICODE_STRING lpFileNameW;
+ WIN32_FIND_DATAW FindFileDataW;
+
+ lpFileNameW = Basep8BitStringToStaticUnicodeString(lpFileName);
+ if (!lpFileNameW)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ hSearch = FindFirstFileExW(lpFileNameW->Buffer,
+ fInfoLevelId,
+ &FindFileDataW,
+ fSearchOp,
+ lpSearchFilter,
+ dwAdditionalFlags);
+ if (hSearch == INVALID_HANDLE_VALUE)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ memcpy(lpFindFileData, &FindFileDataW, FIELD_OFFSET(WIN32_FIND_DATA,
cFileName));
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cFileName);
+ Ansi.Buffer = ((LPWIN32_FIND_DATAA)lpFindFileData)->cFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = MAX_PATH;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ FindClose(hSearch);
+ BaseSetLastNTError(Status);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ RtlInitUnicodeString(&UTF8, FindFileDataW.cAlternateFileName);
+ Ansi.Buffer = ((LPWIN32_FIND_DATAA)lpFindFileData)->cAlternateFileName;
+ Ansi.Length = 0;
+ Ansi.MaximumLength = 14;
+ Status = BasepUnicodeStringTo8BitString(&Ansi, &UTF8, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ FindClose(hSearch);
+ BaseSetLastNTError(Status);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ return hSearch;
}