From df856f976bd0ae1e57e1b1c2ed112f918d4a64bc Mon Sep 17 00:00:00 2001 From: ashok Date: Thu, 19 Mar 2015 10:41:28 +0000 Subject: Ticket [e66e444440]. Modified ReadConsoleBytes to handle Ctrl-C / Ctrl-Break and not return 0 bytes indicating EOF for those cases. --- win/tclWinConsole.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index 63150ef..7380003 100644 --- a/win/tclWinConsole.c +++ b/win/tclWinConsole.c @@ -220,8 +220,20 @@ ReadConsoleBytes( BOOL result; int tcharsize = sizeof(TCHAR); - result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars, - NULL); + /* + * If user types a Ctrl-Break or Ctrl-C, ReadConsole will return + * success with ntchars == 0 and GetLastError() will be + * ERROR_OPERATION_ABORTED. We do not want to treat this case + * as EOF so we will loop around again. If no Ctrl signal handlers + * have been established, the default signal OS handler in a separate + * thread will terminate the program. If a Ctrl signal handler + * has been established (through an extension for example), it + * will run and take whatever action it deems appropriate. + */ + do { + result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars, + NULL); + } while (result && ntchars == 0 && GetLastError() == ERROR_OPERATION_ABORTED); if (nbytesread != NULL) { *nbytesread = ntchars * tcharsize; } -- cgit v0.12