mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 00:43:09 +00:00
[CMD] TYPE: Rewrite the command so as to fix some of its behaviour.
- Display the names of the files being TYPEd only if more than one file has been specified on the command-line, or if a file specification (with wildcards) is present (even just for one). These names are displayed on STDERR while the files are TYPEd on STDOUT, therefore allowing concatenating files by just redirecting STDOUT to a destination, without corrupting it with the displayed file names. Also, add a /N option to force not displaying these file names. - When file specifications (with wildcards) are being processed, silently ignore any directories matching them. If no corresponding files have been found, display a file-not-found error. - When explicitly directory names are specified, don't do any special treatment; the CreateFile() call will fail and return the appropriate error. - Fix the returned errorlevel values. See https://ss64.com/nt/type.html for more information. Fixes some cmd_winetests. - When reading from a file, retrieve its original size so that we can stop reading it once we are beyond its original ending. This allows avoiding an infinite read loop in case the output of the file is redirected back to it. Fixes CORE-17208 - Move the FileGetString() helper to the only file where it is actually used.
This commit is contained in:
parent
3d4af22328
commit
6a8754c83a
3 changed files with 293 additions and 108 deletions
|
@ -510,45 +510,6 @@ BOOL IsExistingDirectory (LPCTSTR pszPath)
|
|||
}
|
||||
|
||||
|
||||
BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
|
||||
{
|
||||
LPSTR lpString;
|
||||
DWORD dwRead;
|
||||
INT len = 0;
|
||||
#ifdef _UNICODE
|
||||
lpString = cmd_alloc(nBufferLength);
|
||||
#else
|
||||
lpString = lpBuffer;
|
||||
#endif
|
||||
|
||||
if (ReadFile(hFile, lpString, nBufferLength - 1, &dwRead, NULL))
|
||||
{
|
||||
/* break at new line*/
|
||||
CHAR *end = memchr(lpString, '\n', dwRead);
|
||||
len = dwRead;
|
||||
if (end)
|
||||
{
|
||||
len = (INT)(end - lpString) + 1;
|
||||
SetFilePointer(hFile, len - dwRead, NULL, FILE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
if (!len)
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
cmd_free(lpString);
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
lpString[len++] = '\0';
|
||||
#ifdef _UNICODE
|
||||
MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
|
||||
cmd_free(lpString);
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// See r874
|
||||
BOOL __stdcall PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue