Author: hbelusca
Date: Sun May 10 12:25:27 2015
New Revision: 67619
URL:
http://svn.reactos.org/svn/reactos?rev=67619&view=rev
Log:
[NTVDM]: Fix DOS file find. Introduced in r61507, it was indeed untested...
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c [iso-8859-1] Sun May 10 12:25:27 2015
@@ -546,65 +546,87 @@
{
BOOLEAN Success = TRUE;
WIN32_FIND_DATAA FindData;
+ HANDLE SearchHandle;
PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData;
+
+ /* Start a search */
+ SearchHandle = FindFirstFileA(FileName, &FindData);
+ if (SearchHandle == INVALID_HANDLE_VALUE) return GetLastError();
+
+ do
+ {
+ /* Check the attributes and retry as long as we haven't found a matching file
*/
+ if (((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_DIRECTORY))
+ & ~AttribMask))
+ {
+ break;
+ }
+ }
+ while ((Success = FindNextFileA(SearchHandle, &FindData)));
+
+ /* If we failed at some point, close the search and return an error */
+ if (!Success)
+ {
+ FindClose(SearchHandle);
+ return GetLastError();
+ }
/* Fill the block */
FindFileBlock->DriveLetter = CurrentDrive + 'A';
FindFileBlock->AttribMask = AttribMask;
- FindFileBlock->SearchHandle = FindFirstFileA(FileName, &FindData);
- if (FindFileBlock->SearchHandle == INVALID_HANDLE_VALUE) return GetLastError();
+ FindFileBlock->SearchHandle = SearchHandle;
+ FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
+ FileTimeToDosDateTime(&FindData.ftLastWriteTime,
+ &FindFileBlock->FileDate,
+ &FindFileBlock->FileTime);
+ FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF
+ : FindData.nFileSizeLow;
+ /* Build a short path name */
+ if (*FindData.cAlternateFileName)
+ strncpy(FindFileBlock->FileName, FindData.cAlternateFileName,
sizeof(FindFileBlock->FileName));
+ else
+ GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName,
sizeof(FindFileBlock->FileName));
+
+ return ERROR_SUCCESS;
+}
+
+DWORD
+WINAPI
+demFileFindNext(OUT PVOID lpFindFileData)
+{
+ WIN32_FIND_DATAA FindData;
+ PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData;
do
{
- /* Check the attributes */
- if (!((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
- FILE_ATTRIBUTE_SYSTEM |
- FILE_ATTRIBUTE_DIRECTORY))
- & ~AttribMask))
- {
- break;
- }
- }
- while ((Success = FindNextFileA(FindFileBlock->SearchHandle, &FindData)));
-
- if (!Success) return GetLastError();
-
+ /* Continue searching as long as we haven't found a matching file */
+
+ /* If we failed at some point, close the search and return an error */
+ if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData))
+ {
+ FindClose(FindFileBlock->SearchHandle);
+ return GetLastError();
+ }
+ }
+ while ((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_DIRECTORY))
+ & ~FindFileBlock->AttribMask);
+
+ /* Update the block */
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
FileTimeToDosDateTime(&FindData.ftLastWriteTime,
&FindFileBlock->FileDate,
&FindFileBlock->FileTime);
FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF
: FindData.nFileSizeLow;
- strcpy(FindFileBlock->FileName, FindData.cAlternateFileName);
-
- return ERROR_SUCCESS;
-}
-
-DWORD
-WINAPI
-demFileFindNext(OUT PVOID lpFindFileData)
-{
- WIN32_FIND_DATAA FindData;
- PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData;
-
- do
- {
- if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData))
- return GetLastError();
-
- /* Update the block */
- FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
- FileTimeToDosDateTime(&FindData.ftLastWriteTime,
- &FindFileBlock->FileDate,
- &FindFileBlock->FileTime);
- FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF
- : FindData.nFileSizeLow;
- strcpy(FindFileBlock->FileName, FindData.cAlternateFileName);
- }
- while((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
- FILE_ATTRIBUTE_SYSTEM |
- FILE_ATTRIBUTE_DIRECTORY))
- & ~FindFileBlock->AttribMask);
+ /* Build a short path name */
+ if (*FindData.cAlternateFileName)
+ strncpy(FindFileBlock->FileName, FindData.cAlternateFileName,
sizeof(FindFileBlock->FileName));
+ else
+ GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName,
sizeof(FindFileBlock->FileName));
return ERROR_SUCCESS;
}