Skip to content

Commit c380c2c

Browse files
committed
[CMD]
- Fix some comments that were otherwise hard to understand. - Don't hardcode MAX_PATH in some API calls but instead use the real array char size. - Don't leak find-file handles: fix leaked handles to NUL pseudo-file in situations where we do: copy some_file+NUL some_dest_file . Should fix some cmd winetests. svn path=/trunk/; revision=67055
1 parent b696813 commit c380c2c

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

reactos/base/shell/cmd/copy.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,12 @@ INT cmd_copy(LPTSTR param)
341341
WIN32_FIND_DATA findBuffer;
342342
HANDLE hFile = NULL;
343343
BOOL bTouch = FALSE;
344-
/* Used when something like "copy c*.exe d*.exe" during the process of
345-
figuring out the new name */
346344
/* Pointer to keep track of how far through the append input(file1+file2+file3) we are */
347345
TCHAR * appendPointer = _T("\0");
348346
/* The full path to src and dest. This has drive letter, folders, and filename */
349347
TCHAR tmpDestPath[MAX_PATH];
350348
TCHAR tmpSrcPath[MAX_PATH];
351-
/* A bool on weather or not the destination name will be taking from the input */
349+
/* A bool to know whether or not the destination name will be taken from the input */
352350
BOOL bSrcName = FALSE;
353351
/* Seems like a waste but it is a pointer used to copy from input to PreserveName */
354352
TCHAR * UseThisName;
@@ -357,6 +355,7 @@ INT cmd_copy(LPTSTR param)
357355
int size;
358356
TCHAR * szTouch;
359357
BOOL bHasWildcard, bDone = FALSE, bMoreFiles = FALSE;
358+
/* Used for something like "copy c*.exe d*.exe" */
360359
BOOL bMultipleSource = FALSE, bMultipleDest = FALSE;
361360

362361

@@ -369,7 +368,7 @@ INT cmd_copy(LPTSTR param)
369368

370369
nErrorLevel = 0;
371370

372-
/* Get the envor value if it exists */
371+
/* Get the env variable value if it exists */
373372
evar = cmd_alloc(512 * sizeof(TCHAR));
374373
if (evar == NULL)
375374
size = 0;
@@ -578,27 +577,27 @@ INT cmd_copy(LPTSTR param)
578577
bMultipleSource = TRUE;
579578
}
580579

581-
/* Reusing the number of files variable */
580+
/* Reuse the number of files variable */
582581
nFiles = 0;
583582

584583
/* Check if no destination argument is passed */
585584
if (nDes == -1)
586585
{
587586
/* If no destination was entered then just use
588587
the current directory as the destination */
589-
GetCurrentDirectory(MAX_PATH, szDestPath);
588+
GetCurrentDirectory(ARRAYSIZE(szDestPath), szDestPath);
590589
}
591590
else
592591
{
593592
/* Check if the destination is 'x:' */
594593
if ((arg[nDes][1] == _T(':')) && (arg[nDes][2] == _T('\0')))
595594
{
596-
GetRootPath(arg[nDes], szDestPath, MAX_PATH);
595+
GetRootPath(arg[nDes], szDestPath, ARRAYSIZE(szDestPath));
597596
}
598597
else
599598
{
600599
/* If the user entered two file names then form the full string path */
601-
GetFullPathName(arg[nDes], MAX_PATH, szDestPath, NULL);
600+
GetFullPathName(arg[nDes], ARRAYSIZE(szDestPath), szDestPath, NULL);
602601
}
603602

604603
/* Make sure there is an ending slash to the path if the dest is a folder */
@@ -618,12 +617,12 @@ INT cmd_copy(LPTSTR param)
618617
}
619618
}
620619

621-
if (nDes != -1) /* you can only append files when there is a destination */
620+
if (nDes != -1) /* Append files only when there is a destination */
622621
{
623622
if (bMultipleSource && !bMultipleDest)
624623
{
625624
/* We have multiple source files, but not multiple destination
626-
files. This means we are appending the soruce files. */
625+
files. This means we are appending the source files. */
627626
bAppend = TRUE;
628627
if (_tcschr(arg[nSrc], _T('|')) != NULL)
629628
appendPointer = arg[nSrc];
@@ -662,7 +661,7 @@ INT cmd_copy(LPTSTR param)
662661
szSrcPath[0] = _T('\0');
663662

664663
/* Loop through the source file name and copy all
665-
the chars one at a time until it gets too + */
664+
the chars one at a time until we reach the separator */
666665
while(TRUE)
667666
{
668667
if (appendPointer[0] == _T('|'))
@@ -685,7 +684,7 @@ INT cmd_copy(LPTSTR param)
685684
{
686685
/* Only time there is a , in the source is when they are using touch
687686
Cant have a destination and can only have on ,, at the end of the string
688-
Cant have more then one file name */
687+
Cant have more than one file name */
689688
szTouch = _tcsstr(arg[nSrc], _T("|"));
690689
if (_tcsncmp(szTouch,_T("|,,\0"), 4) || (nDes != -1))
691690
{
@@ -714,8 +713,8 @@ INT cmd_copy(LPTSTR param)
714713
}
715714

716715

717-
/* From this point on, we can assume that the shortest path is 3 letters long
718-
and that would be [DriveLetter]:\ */
716+
/* From this point on, we can assume that the shortest path is
717+
3 letters long and that would be [DriveLetter]:\ */
719718

720719
/* Check if the path has a wildcard */
721720
bHasWildcard = (_tcschr(szSrcPath, _T('*')) != NULL);
@@ -742,10 +741,10 @@ INT cmd_copy(LPTSTR param)
742741
/* Get a list of all the files */
743742
hFile = FindFirstFile(szSrcPath, &findBuffer);
744743

745-
/* If it couldnt open the file handle, print out the error */
744+
/* If we could not open the file handle, print out the error */
746745
if (hFile == INVALID_HANDLE_VALUE)
747746
{
748-
/* only print source name when more then one file */
747+
/* only print source name when more than one file */
749748
if (bMultipleSource)
750749
ConOutPrintf(_T("%s\n"), szSrcPath);
751750

@@ -757,10 +756,12 @@ INT cmd_copy(LPTSTR param)
757756

758757
/* Strip the paths back to the folder they are in */
759758
for (i = (_tcslen(szSrcPath) - 1); i > -1; i--)
759+
{
760760
if (szSrcPath[i] != _T('\\'))
761761
szSrcPath[i] = _T('\0');
762762
else
763763
break;
764+
}
764765

765766
do
766767
{
@@ -803,7 +804,7 @@ INT cmd_copy(LPTSTR param)
803804
_tcscat(tmpDestPath, findBuffer.cFileName);
804805
else
805806
{
806-
/* If there is no wildcard you can use the name the user entered */
807+
/* If there is no wildcard, use the name the user entered */
807808
if ((_tcschr(UseThisName, _T('*')) == NULL) &&
808809
(_tcschr(UseThisName, _T('?')) == NULL))
809810
{
@@ -836,7 +837,7 @@ INT cmd_copy(LPTSTR param)
836837
break;
837838
}
838839

839-
/* only print source name when more then one file */
840+
/* only print source name when more than one file */
840841
if (bMultipleSource)
841842
ConOutPrintf(_T("%s\n"), tmpSrcPath);
842843

@@ -848,11 +849,10 @@ INT cmd_copy(LPTSTR param)
848849
if (nOverwrite == PROMPT_ALL || (nOverwrite == PROMPT_YES && bAppend))
849850
dwFlags |= COPY_NO_PROMPT;
850851

851-
/* Tell weather the copy was successful or not */
852+
/* Tell whether the copy was successful or not */
852853
if (copy(tmpSrcPath,tmpDestPath, bAppend, dwFlags, bTouch))
853854
{
854855
nFiles++;
855-
//LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, ARRAYSIZE(szMsg));
856856
}
857857
else
858858
{
@@ -865,14 +865,14 @@ INT cmd_copy(LPTSTR param)
865865
/* Loop through all wildcard files */
866866
} while (FindNextFile(hFile, &findBuffer));
867867

868+
FindClose(hFile);
869+
868870
/* Loop through all files in src string with a + */
869-
} while(!bDone);
871+
} while (!bDone);
870872

871873
/* print out the number of files copied */
872874
ConOutResPrintf(STRING_COPY_FILE, bAppend ? 1 : nFiles);
873875

874-
if (hFile) FindClose(hFile);
875-
876876
if (arg != NULL)
877877
freep(arg);
878878

0 commit comments

Comments
 (0)