Author: cfinck Date: Sun Jul 29 23:53:17 2007 New Revision: 28022
URL: http://svn.reactos.org/svn/reactos?rev=28022&view=rev Log: Various cmd fixes by Carlo Bramini (carlo DOT bramix AT libero DOT it) See issue #2232 for more details.
Modified: trunk/reactos/base/shell/cmd/copy.c trunk/reactos/base/shell/cmd/filecomp.c trunk/reactos/base/shell/cmd/misc.c
Modified: trunk/reactos/base/shell/cmd/copy.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/copy.c?rev=2... ============================================================================== --- trunk/reactos/base/shell/cmd/copy.c (original) +++ trunk/reactos/base/shell/cmd/copy.c Sun Jul 29 23:53:17 2007 @@ -66,7 +66,6 @@ DWORD dwAttrib; DWORD dwRead; DWORD dwWritten; - DWORD i; BOOL bEof = FALSE; TCHAR TrueDest[MAX_PATH]; TCHAR TempSrc[MAX_PATH]; @@ -168,7 +167,6 @@ }
- if (!IsExistingFile (dest)) { #ifdef _DEBUG @@ -231,7 +229,9 @@ nErrorLevel = 1; return 0; } - buffer = (LPBYTE)malloc (BUFF_SIZE); + + /* A page-aligned buffer usually give more speed */ + buffer = (LPBYTE)VirtualAlloc(NULL, BUFF_SIZE, MEM_COMMIT, PAGE_READWRITE); if (buffer == NULL) { CloseHandle (hFileDest); @@ -247,16 +247,13 @@ ReadFile (hFileSrc, buffer, BUFF_SIZE, &dwRead, NULL); if (lpdwFlags & COPY_ASCII) { - for (i = 0; i < dwRead; i++) - { - /* we're dealing with ASCII files! */ - if (((LPSTR)buffer)[i] == 0x1A) - { - bEof = TRUE; - break; - } - } - dwRead = i; + LPBYTE pEof = memchr(buffer, 0x1A, dwRead); + if (pEof != NULL) + { + bEof = TRUE; + dwRead = pEof-buffer+1; + break; + } }
if (dwRead == 0) @@ -274,25 +271,24 @@ return 0; } } - while (dwRead && !bEof); + while (!bEof);
#ifdef _DEBUG DebugPrintf (_T("setting time\n")); #endif SetFileTime (hFileDest, &srctime, NULL, NULL);
- if (lpdwFlags & COPY_ASCII) + if ((lpdwFlags & COPY_ASCII) && !bEof) { /* we're dealing with ASCII files! */ - ((LPSTR)buffer)[0] = 0x1A; - ((LPSTR)buffer)[1] = '\0'; + buffer[0] = 0x1A; #ifdef _DEBUG DebugPrintf (_T("appending ^Z\n")); #endif WriteFile (hFileDest, buffer, sizeof(CHAR), &dwWritten, NULL); }
- free (buffer); + VirtualFree (buffer, 0, MEM_RELEASE); CloseHandle (hFileDest); CloseHandle (hFileSrc);
@@ -317,8 +313,6 @@
if(lpdwFlags & COPY_DECRYPT) DeleteFile(TempSrc); - -
return 1; } @@ -877,7 +871,7 @@ LoadString(CMD_ModuleHandle, STRING_COPY_FILE, szMsg, RC_STRING_MAX_SIZE); ConOutPrintf(szMsg, nFiles); - CloseHandle(hFile); + FindClose(hFile); if (arg!=NULL) free(arg);
Modified: trunk/reactos/base/shell/cmd/filecomp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/filecomp.c?r... ============================================================================== --- trunk/reactos/base/shell/cmd/filecomp.c (original) +++ trunk/reactos/base/shell/cmd/filecomp.c Sun Jul 29 23:53:17 2007 @@ -473,7 +473,8 @@ _tcscpy(szSuffix,&strIN[SBreak]); strIN[PBreak] = _T('\0'); _tcscpy(szPrefix,strIN); - if(szPrefix[_tcslen(szPrefix) - 2] == _T('"')) + if (szPrefix[_tcslen(szPrefix) - 2] == _T('"') && + szPrefix[_tcslen(szPrefix) - 1] != _T(' ')) { /* need to remove the " right before a \ at the end to allow the next stuff to stay inside one set of quotes @@ -604,21 +605,17 @@ } /* search for the files it might be */ hFile = FindFirstFile (szSearchPath, &file); - + if(hFile == INVALID_HANDLE_VALUE) + { + /* Assemble the orginal string and return */ + _tcscpy(strOut,szOrginal); + return; + } + /* aseemble a list of all files names */ do { - if(hFile == INVALID_HANDLE_VALUE) - { - /* Assemble the orginal string and return */ - _tcscpy(strOut,szOrginal); - CloseHandle(hFile); - if(FileList != NULL) - free(FileList); - return; - } - - if(!_tcscmp (file.cFileName, _T(".")) || + if(!_tcscmp (file.cFileName, _T(".")) || !_tcscmp (file.cFileName, _T(".."))) continue; @@ -631,36 +628,28 @@ }
/* Add the file to the list of files */ - if(FileList == NULL) - { - FileListSize = 1; - FileList = malloc(FileListSize * sizeof(FileName)); - } - else - { - FileListSize++; - FileList = realloc(FileList, FileListSize * sizeof(FileName)); - } + FileList = realloc(FileList, ++FileListSize * sizeof(FileName));
if(FileList == NULL) { /* Assemble the orginal string and return */ _tcscpy(strOut,szOrginal); - CloseHandle(hFile); + FindClose(hFile); ConOutFormatMessage (GetLastError()); return; } /* Copies the file name into the struct */ _tcscpy(FileList[FileListSize-1].Name,file.cFileName);
- }while(FindNextFile(hFile,&file)); + } while(FindNextFile(hFile,&file)); + + FindClose(hFile);
/* Check the size of the list to see if we found any matches */ if(FileListSize == 0) { _tcscpy(strOut,szOrginal); - CloseHandle(hFile); if(FileList != NULL) free(FileList); return; @@ -751,7 +740,6 @@ _tcscpy(LastReturned,strOut); EndLength = _tcslen(strOut); DiffLength = EndLength - StartLength; - CloseHandle(hFile); if(FileList != NULL) free(FileList);
Modified: trunk/reactos/base/shell/cmd/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=2... ============================================================================== --- trunk/reactos/base/shell/cmd/misc.c (original) +++ trunk/reactos/base/shell/cmd/misc.c Sun Jul 29 23:53:17 2007 @@ -142,7 +142,7 @@ _tcscat(TempPath, _T("\")); _tcscat(OutPath, FindFileData.cFileName); _tcscat(OutPath, _T("\")); - CloseHandle(hFind); + FindClose(hFind); } } }