more.c should not close INVALID_HANDLE_VALUE

patch by Apal
remove tab and quit when failing to open file (tested with Windows XP SP2)

svn path=/trunk/; revision=28426
This commit is contained in:
Johannes Anderwald 2007-08-19 20:16:10 +00:00
parent 82f18756f0
commit b4c3f2b5e3

View file

@ -116,25 +116,28 @@ int main (int argc, char **argv)
buff=malloc(4096);
FlushConsoleInputBuffer (hKeyboard);
FlushConsoleInputBuffer (hKeyboard);
if(argc > 1)
{
GetFullPathName(argv[1], MAX_PATH, szFullPath, NULL);
hFile = CreateFile (szFullPath, GENERIC_READ,
0,NULL,OPEN_ALWAYS,0,0);
if (hFile == INVALID_HANDLE_VALUE)
{
ConOutPuts(_T("The file could not be opened"));
return 0;
}
}
else
{
hFile = hStdIn;
}
do
{
if(hFile != INVALID_HANDLE_VALUE)
{
bRet = ReadFile(hFile,buff,4096,&dwRead,NULL);
}
else
{
bRet = ReadFile(hStdIn,buff,4096,&dwRead,NULL);
}
bRet = ReadFile(hFile,buff,4096,&dwRead,NULL);
for(last=i=0;i<dwRead && bRet;i++)
{
@ -161,7 +164,8 @@ int main (int argc, char **argv)
free (buff);
CloseHandle (hKeyboard);
CloseHandle (hFile);
if (hFile != hStdIn)
CloseHandle (hFile);
return 0;
}